原文:
docker安装MySQL8,目录挂载、配置用户名密码、忽略表名大小写、连接数、特殊字符、时区
一、环境配置
1、系统:centos7.3
2、docker版本:Docker version 1.13.1, build 07f3374/1.13.1
3、MySQL镜像:mysql
4、MySQL版本:8.0.13
二、安装部署
1、创建容器
docker run -di --name=mysql \
-v /usr/local/src/mysql/data:/var/lib/mysql \
-v /usr/local/src/mysql/conf/my.cnf:/etc/mysql/my.cnf \
--privileged=true \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=123456 mysql \
--lower_case_table_names=1
执行效果如图所示:
2、配置my.cnf
① 将/usr/local/src/mysql/conf/目录下my.cnf的这个目录删除,rm -rf my.cnf/
② /usr/local/src/mysql/conf/目录下新建my.cnf文件,文件内容如下所示:
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_connections=10000
default-time_zone='+8:00'
character-set-client-handshake=FALSE
character_set_server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci'
# Custom config should go here
!includedir /etc/mysql/conf.d/
3、启动mysql容器
docker start mysql
效果如图所示:
4、修改权限密码方式
① 进入mysql容器
docker exec -it mysql /bin/bash
② 登录mysql(PS:密码123456)
mysql -u root -p
③ 执行修改脚本
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;
效果如图所示:
5、测试,Navicat进行测试,其他工具也可以
恭喜你安装成功!
TKS!