sudo docker pull mysql:5.7
docker run -d --name mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql/conf.d \
-v /mydata/mysql/log:/logs \
-e MYSQL_ROOT_PASSWORD='Jcxg*b6$btHr&acg' \
-p 3306:3306 \
-d mysql:5.7 \
--lower_case_table_names=1
–name指定容器名字 -v目录挂载 -p指定端口映射 -e设置mysql参数 -d后台运行
docker ps
vi /mydata/mysql/conf/my.conf
将以下内容复制到文本
[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
lower_case_table_names=1
default-time_zone = '+8:00'
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
default-time_zone = '+8:00'
docker restart mysql
docker update mysql --restart=always
1、开放防火墙3306端口
firewall-cmd --permanent --add-port=3306/tcp
2、开放阿里云服务器3306端口
3、修改sshd_config文件
vi /etc/ssh/sshd_config
修改 PasswordAuthentication yes
重启ssh
systemctl restart sshd.service
SELECT @@GLOBAL.sql_mode
SELECT @@SESSION.sql_mode;
select @@sql_mode
set @@GLOBAL.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
set @@SESSION.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';