docker 安装MySQL

docker pull mysql:5.7 # 拉取 mysql 5.7

docker run -p 3306:3306 --name mysql
-v /home/docker-v/mysql/conf:/etc/mysql
-v /home/docker-v/mysql/logs:/var/log/mysql
-v /home/docker-v/mysql/data:/var/lib/mysql
-e MYSQL_ROOT_PASSWORD=123456
-d mysql:5.7

–name:容器名,此处命名为mysql
-e:配置信息,此处配置mysql的root用户的登陆密码
-p:端口映射,此处映射 主机3306端口 到 容器的3306端口
-d:后台运行容器,保证在退出终端后容器继续运行

sudo docker exec -it mysql bash
mysql -uroot -p123456
mysql> grant all privileges on . to root@'%' identified by "password";

mysql> use mysql;
Database changed

mysql> select host,user from user;

mysql> grant all privileges on . to root@'%' identified by "123456";
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

上一篇:使用MysqlProxy 实现读写分离


下一篇:10补交