0.拉取镜像
sudo docker pull mysql:5.7
1.创建存放映射文件夹
mkdir -p mydata/mysql/log
mkdir -p mydata/mysql/data
mkdir -p mydata/mysql/conf
2.docker run
sudo docker run -p 3306:3306 --name mysql
-v /mydata/mysql/log:/var/log/mysql
-v /mydata/mysql/data:/var/lib/mysql
-v /mydata/mysql/conf:/etc/mysql
-e MYSQL_ROOT_PASSWORD=password
-d mysql:5.7
3.修改配置文件
切换到conf目录下
touch my.cnf
touch my.conf先修改my.conf配置
vi /mydata/mysql/conf/my.conf
下面是my.conf配置文件内容
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve再修改my.cnf配置
vi /mydata/mysql/conf/my.cnf
下面是my.cnf配置文件内容
[mysqld]
log-bin=/var/lib/mysql/mysql-bin
server-id=123654
expire_logs_days = 30
保存之后执行下面操作
- docker restart mysql #重启mysql
- docker exec -it mysql bin/bash #docker启动mysql客户端
- mysql -u root -p
- show variables like '%log_bin%'; #查看是否生效
log_bin : ON binlog开启成功
参考:https://www.freebytes.net/it/java/dokcer-mysql-binlog.html