docker offline installation mysql
- Step 1: Find a networked server with docker installed, check the current docker image:
docker images
, pull the mysql image package:docker save -o mysql.tar mysql:latest
, where latest is the content of the tag line
-
Step 2: Copy the downloaded mysql.tar to
/opt/soft
the folder -
Step 3: Run the command to load the mysql image:
docker load -i mysql.tar
-
Step 4: View the docker image:
docker images
, and find that it contains the mysql image -
Step 5: Create mysql container:
docker run -p 3306:3306 --name mysql --restart=always --privileged=true \ -v /usr/local/mysql/log:/var/log/mysql \ -v /usr/local/mysql/data:/var/lib/mysql \ -v /usr/local/mysql/conf:/etc/mysql \ -v /etc/localtime:/etc/localtime:ro \ -e MYSQL_ROOT_PASSWORD=123456 -d mysql:latest
explain:
-p 3306:3306:指定宿主机端口与容器端口映射关系 --name mysql:创建的容器名称 --restart=always:总是跟随docker启动 --privileged=true:获取宿主机root权限 -v /usr/local/mysql/log:/var/log/mysql:映射日志目录,宿主机:容器 -v /usr/local/mysql/data:/var/lib/mysql:映射数据目录,宿主机:容器 -v /usr/local/mysql/conf:/etc/mysql:映射配置目录,宿主机:容器 -v /etc/localtime:/etc/localtime:ro:让容器的时钟与宿主机时钟同步,避免时区的问题,ro是read only的意思,就是只读。 -e MYSQL_ROOT_PASSWORD=123456:指定mysql环境变量,root用户的密码为123456 -d mysql:latest:后台运行mysql容器,版本是latest。
-
Step 6: Check whether the installation is successful:
docker ps -a
If the status is restarting, put the my.cnf configuration file in the directory:/usr/local/mysql/conf
and restart mysql to make the configuration take effect:docker restart mysql
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 # 限制导入和导出的数据目录 # 为空,不限制导入到处的数据目录; # 指定目录,必须从该目录导入到处,且MySQL不会自动创建该目录; # 为NULL,禁止导入与导出功能 #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
-
Step 7: Enter the container interaction interface:
docker exec -it mysqlserver bash
-
Step 8:
mysql -u root -p
If my.cnf in Step 6 is configured in front, do not enter the password and press Enter directly to enter. Remember to change the password authentication method:
ALTER USER root@'%' IDENTIFIED WITH mysql_native_password BY '123456';
-
Step 9: Open remote connection permissions
use mysql select host,user from user; update user set host='%' where user='root'; flush privileges;
-
Step 10: navicat tests connection to mysql