前言:
此刻兄弟们对“centosmysql目录”都比较关心,我们都想要学习一些“centosmysql目录”的相关文章。那么小编也在网摘上汇集了一些关于“centosmysql目录””的相关内容,希望大家能喜欢,各位老铁们快快来学习一下吧!一、新建MySQL5容器
1、mysql镜像
方式一:
docker pull mysql:5.7方式二:
使用BT面板或者portainer的docker管理器拉取镜像
查看镜像
[root@iZwz9b3eh8po9pclw9gi5cZ data]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/xql19218/centos_django1 v1 050365746566 15 hours ago 542 MBdocker.io/portainer/portainer latest 19d07168491a 9 days ago 74.1 MBdocker.io/mysql 5.7 ee7cbd482336 9 days ago 372 MB
2、创建mysql容器
方式一:
使用命令创建
docker run -p 8080:3306 --name mymysql57 -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/mysql_data -e MYSQL_ROOT_PASSWORD=123456 -d docker.io/mysql:5.7
说明:
--name mymysql57:容器名字-p 8080:3306:将容器的3306端口映射到主机的8080端口-v -v $PWD/conf:/etc/mysql/conf.d:将主机当前目录下的conf/my.cnf挂载到容器的/etc/mysql/my.cnf-v $PWD/logs:/logs:将主机当前目录下的logs目录挂载到容器的/logs-v $PWD/data:/mysql_data:将主机当前目录下的data目录挂载到容器的/mysql_data-e MYSQL_ROOT_PASSWORD=123456:初始化root用户的密码--lower_case_table_names=1 设置表名参数名等忽略大小写 -v /etc/localtime:/etc/localtime:ro 设置容器的时间与宿主机同步方式二:
使用docker管理器创建
查看容器
[root@iZwz9b3eh8po9pclw9gi5cZ data]# docker container lsCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES179892b67bbd docker.io/mysql:5.7 "docker-entrypoint..." 14 seconds ago Up 13 seconds 33060/tcp, 0.0.0.0:8080->3306/tcp mymysql57
3、使用Navicat等工具连接测试
输入IP地址账号密码的连接成功则表示创建成功
注意:需要开放相关端口,远程连接端口为宿主机端口(8080),否则连接失败
二、 配置mysql
1、进入mysql容器
data]# docker exec -it 1798 bashroot@179892b67bbd:/#
2、重置root密码
进入mysql
root@179892b67bbd:/# mysql -uroot -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 5Server version: 5.7.25 MySQL Community Server (GPL)Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>修改root密码
mysql> SET PASSWORD = PASSWORD('12345678');Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;Query OK, 0 rows affected (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql>
原始密码:123456
修改后密码:12345678
退出使用新密码登录
mysql> quit;Byeroot@179892b67bbd:/# mysql -uroot -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 6Server version: 5.7.25 MySQL Community Server (GPL)Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
3、设置远程连接密码
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '12345678' WITH GRANT OPTION;Query OK, 0 rows affected, 1 warning (0.00 sec)
密码是:12345678
使用使用新密码在Navicat远程连接成功
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #centosmysql目录 #centos7dockerredis #在centos7的mysql修改时间 #docker22centos7配置