docker pull mysql:8
在/dp/docker/file/mysql/conf/下创建mysql配置文件my.cnf
注意权限不要太高chmod 644就可以不要777太高会被忽略
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
port=3306
max_connections = 2000
mysqlx_max_connections = 2000
#表名设置成小写、查询时不区分大小写
lower_case_table_names = 1
wait_timeout=120
interactive_timeout=120
character-set-server = utf8mb4
collation-server = utf8mb4_0900_ai_ci
group_concat_max_len = 102400
#如果上次启动失败了,注意在启动前要把本地/docker/mysql/清空 除了conf/
执行后再查看一下启动日志有没有异常
docker run -p 3306:3306 --name mysql02 --restart=always --privileged=true \
-v /dp/docker/file/mysql02/log:/var/log/mysql \
-v /dp/docker/file/mysql02/data:/var/lib/mysql \
-v /dp/docker/file/mysql02/conf:/etc/mysql \
-v /dp/docker/file/mysql02/files:/var/lib/mysql-files \
-v /etc/localtime:/etc/localtime:ro \
-v /dp/docker/file/mysql02/conf/my.cnf:/etc/my.cnf \
-e TZ="Asia/Shanghai" \
-e MYSQL_ROOT_PASSWORD=root -d mysql:latest --lower_case_table_names=1
到这就可以了,更多配置可以登录容器,如:
root身份登录容器
docker exec -ti -u root mysql02 bash
登录mysql
mysql -uroot -p
use mysql
修改密码和登录IP限制
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新密码';
flush privileges;