1. 拉取镜像
docker pull mysql:8.0.28
2. 启动容器
docker run -d --name mysql -p 23306:3306 -e MYSQL_ROOT_PASSWORD=Abcd@2023! mysql:8.0
3. 修改密码(备用)
- 进入容器
docker exec -it mysql bash
mysql -uroot -p123456 use mysql
修改密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新密码'
刷新权限
flush privileges
4. 同步时间
docker cp /usr/share/zoneinfo/Asia/Shanghai mysql:/etc/localtime
5. Too Many Connections
SHOW VARIABLES LIKE 'max_connections'; SET GLOBAL max_connections=1000; SET GLOBAL wait_timeout=300;