拉取mysql8.0镜像
docker pull mysql:8.0
创建文件夹,位置自己随意
mkdir -p /usr/local/mysql/data &&
mkdir -p /usr/local/mysql/logs &&
mkdir -p /usr/local/mysql/conf
创建配置文件my.cnf
touch /usr/local/mysql/conf/my.cnf
配置信息写入
vim /usr/local/mysql/conf/my.cnf
复制一下内容
[mysqld]
user=mysql
character-set-server=utf8
default_authentication_plugin=mysql_native_password
secure_file_priv=/var/lib/mysql
expire_logs_days=7
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
max_connections=1000
default-character-set=utf8
default-character-set=utf8
启动mysql
docker run --restart=always -p 3306:3306 --name mysql -v /usr/local/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /usr/local/mysql/logs:/var/log/mysql -v /usr/local/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0
docker-mysql默认开启远程连接