The MySQL startup configuration is specified in the file /etc/mysql/my.cnf, and that file in turn includes any files found in the /etc/mysql/conf.d directory that end with .cnf. Settings in files in this directory will augment and/or override settings in /etc/mysql/my.cnf. If you want to use a customized MySQL configuration, you can create your alternative configuration file in a directory on the host machine and then mount that directory location as /etc/mysql/conf.d inside the mysql container.
# docker 中下载 mysql
docker pull mysql
#启动
docker run --name mysql -p 3306:3306-e MYSQL_ROOT_PASSWORD=Lzslov123!-d mysql
#进入容器
docker exec-it mysql bash
#登录mysql
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Lzslov123!';#添加远程登录用户
CREATE USER 'liaozesong'@'%' IDENTIFIED WITH mysql_native_password BY 'Lzslov123!';
GRANT ALL PRIVILEGES ON *.* TO 'liaozesong'@'%';
最新官方MySQL(5.7.19)的docker镜像在创建时映射的配置文件目录有所不同,在此记录并分享给大家:
官方原文:
The MySQL startup configuration is specified in the file
/etc/mysql/my.cnf
, and that file in turn includes any files found in the/etc/mysql/conf.d
directory that end with.cnf
. Settings in files in this directory will augment and/or override settings in/etc/mysql/my.cnf
. If you want to use a customized MySQL configuration, you can create your alternative configuration file in a directory on the host machine and then mount that directory location as/etc/mysql/conf.d
inside themysql
container.大概意思是说:
MySQL(5.7.19)的默认配置文件是 /etc/mysql/my.cnf 文件。如果想要自定义配置,建议向 /etc/mysql/conf.d 目录中创建 .cnf 文件。新建的文件可以任意起名,只要保证后缀名是 cnf 即可。新建的文件中的配置项可以覆盖 /etc/mysql/my.cnf 中的配置项。
具体操作:
首先需要创建将要映射到容器中的目录以及.cnf文件,然后再创建容器
命令说明:
查看容器运行情况
Brian
153***2799@qq.com
1年前 (2017-09-08)
liaozesong
lia***song@yeah.net
参考地址
docker 安装 mysql 8 版本