docker安装mysql
docker pull mysql:8.0
启动mysql容器
docker run -p 3306:3306 --name mysql --restart=always --privileged=true \
-v /app/mysql/log:/var/log/mysql \
-v /app/mysql/data:/var/lib/mysql \
-v /app/mysql/conf:/etc/mysql/conf.d \
-v /etc/localtime:/etc/localtime:ro \
-e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0
cd /app/mysql/conf
vim my.cnf
编辑配置文件
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
# 设置东八区时区
default-time_zone = '+8:00'
# 设置密码验证规则,default_authentication_plugin参数已被废弃
# 改为authentication_policy
#default_authentication_plugin=mysql_native_password
authentication_policy=mysql_native_password
#secure_file_priv=/var/lib/mysql
secure_file_priv=
init_connect='SET collation_connection = utf8mb4_0900_ai_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_0900_ai_ci
skip-character-set-client-handshake
skip-name-resolve
设置自动启动
docker update mysql --restart=always
docker restart mysql
连接不上的话对mysql进行配置:
docker exec -it mysql /bin/bash
mysql -u root -p
show databases;
use mysql;
select host, user, plugin, authentication_string, password_expired from user;
ALTER USER root@'%' IDENTIFIED WITH mysql_native_password BY '123456';
ALTER USER root@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES;