相关: https://blog.csdn.net/jason19905/article/details/81366202
1. docker pull mysql/mysql-server:5.7
2. 创建mysql的数据及配置目录
mkdir /usr/local/docker/mysql/{datadir, conf.d}
3. 初始化命令:
[root@localhost mysql]# docker run --privileged=true -p 3312:3306 \
> --name mysql57 \
> -v /usr/local/docker/mysql/datadir:/var/lib/mysql \
> -v /usr/local/docker/mysql/conf.d:/etc/mysql/conf.d \
> -e MYSQL_ROOT_PASSWORD=163123 mysql/mysql-server:5.7
-p 后的端品映射: 第一个为本机 centos 本的端口,第二个为安装该docker mysql 的(默认)端口;
可能会提示 var/lib/mysql权限问题,加上 –privileged=true
4.支持远程登录:
[root@localhost conf]# docker exec -it mysql57
bash bash-4.2# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 Server version: 5.7.26 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 its affiliates. Other names may be trademarks of their respective owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> grant all privileges on *.* to ‘root’@’%’ identified by ‘xxxxxx’; Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)