一、開始安裝
# 新建掛載目錄
mkdir -p /opt/docker/mysql/data mkdir -p /opt/docker/mysql/conf
vim /opt/docker/mysql/conf/my.cnf
[root@centos01 mysql]# cd conf/
[root@centos01 conf]# ls
my.cnf
[root@centos01 conf]# cat my.cnf
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
lower_case_table_names=1
init_connect='SET NAMES utf8'
max_connections=5000
wait_timeout=20000
max_user_connections=5000
max_allowed_packet=128M
thread_stack=262144
#不區分大小寫 很重要
#lower_case_table_names=1
# 啟動
docker run --restart=always --privileged=true --name mysql8 \
-v /datah/mydata/mysql/conf:/etc/mysql/conf.d \
-v /datah/mydata/mysql/data:/var/lib/mysql \
-p 3307:3306 -e MYSQL_ROOT_PASSWORD='123456' -d mysql
二、修改配置 改密碼
#進入mysql8容器 docker exec -it mysql8 bash
# 如果看到兩個root使用者,刪除一個即可。
opyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select user,host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| root | % |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
mysql>
# 改密碼, 重要的是 mysql_native_password
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';