linux下docker安装mysql8

下载mysql8镜像

docker pull mysql:8

创建mysql容器

mkdir /root
mkdir /root/mysql
mkdir /root/mysql/log/
mkdir /root/mysql/conf/
mkdir /root/mysql/data/
touch /root/mysql/my.cnf
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

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8
docker run -di -p 3306:3306 --privileged=true -v /root/mysql/log:/var/log/mysql -v /root/mysql/data:/var/lib/mysql -v /root/mysql/conf/:/etc/mysql -v /root/mysql/my.cnf:/etc/mysql/my.cnf -e MYSQL_ROOT_PASSWORD=root --name mysql mysql:8
-e MYSQL_ROOT_PASSWORD=root:mysql数据库密码设置为root
--privileged=true:容器内的root拥有真正root权限,否则容器内root只是外部普通用户权限

你可能感兴趣的:(docker)