作者在 2016-12-01 20:18:28 发布以下内容
vi /etc/mysql/mysql.conf.d/mysqld.cnf
#bind-address = 127.0.0.1 #注释掉
启动并进入容器:
docker run -ti --name mysql_base_container -v /var/lib/mysql:/var/lib/mysql mysql_image /bin/bash
初次进入初始化数据库,创建数据库文件夹目录:
mysqld --initialize-insecure
进入容器后启动mysql服务:
service mysql start
登陆mysql:
mysql -u root -p
(空密码,直接回车)
进入以后use mysql数据库:
mysql> use mysql;
添加root用户可以远程访问:
mysql> grant all privileges on *.* to 'root'@'%' identified by 'password123';
mysql> update `mysql`.`user` set `Grant_priv` = 'Y' where `user` = 'root';
mysql> delete from user where user='root' and host='localhost';
mysql> flush privileges;
退出mysql:
mysql> exit
退出容器,保存容器至镜像
docker commit mysql_base_container mysql_image
从镜像正式启动容器:
docker run --name mysql --restart=always -d -p 3306:3306 -v /var/lib/mysql:/var/lib/mysql --entrypoint "/usr/bin/mysqld_safe" mysql_image
大功告成!
#bind-address = 127.0.0.1 #注释掉
启动并进入容器:
docker run -ti --name mysql_base_container -v /var/lib/mysql:/var/lib/mysql mysql_image /bin/bash
初次进入初始化数据库,创建数据库文件夹目录:
mysqld --initialize-insecure
进入容器后启动mysql服务:
service mysql start
登陆mysql:
mysql -u root -p
(空密码,直接回车)
进入以后use mysql数据库:
mysql> use mysql;
添加root用户可以远程访问:
mysql> grant all privileges on *.* to 'root'@'%' identified by 'password123';
mysql> update `mysql`.`user` set `Grant_priv` = 'Y' where `user` = 'root';
mysql> delete from user where user='root' and host='localhost';
mysql> flush privileges;
退出mysql:
mysql> exit
退出容器,保存容器至镜像
docker commit mysql_base_container mysql_image
从镜像正式启动容器:
docker run --name mysql --restart=always -d -p 3306:3306 -v /var/lib/mysql:/var/lib/mysql --entrypoint "/usr/bin/mysqld_safe" mysql_image
大功告成!