docker单机部署 mysql8.0.20
主机新建my.cnf配置文件
[mysqld]
user=mysql
character-set-server=utf8
default_authentication_plugin=mysql_native_password
secure_file_priv=/var/lib/mysql
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
拉取mysql 镜像
[root@master245 ~]# docker pull mysql:8.0.20
运行mysql,并指定端口号3306
[root@master245 ~]# docker run --restart=always --privileged=true -d \
-v /usr/local/docker/mysql/data/:/var/lib/mysql \
-v /usr/local/docker/mysql/logs:/var/log/mysql \
-v /usr/local/docker/mysql/conf.d:/etc/mysql/conf.d \
-v /usr/local/docker/mysql/my.cnf:/etc/mysql/my.cnf \
-p 3306:3306 --name mysql6 \
-e MYSQL_ROOT_PASSWORD=Q12345678 mysql:8.0.20
处理root初始化登录mysql 1045报错
- 修改my.cnf文件,增加skip-grant-tables:
[mysqld]
skip-grant-tables
- 重启mysql docker
[root@master245 ~]# docker restart b6c786506b21
- 进入docker的bash
[root@master245 ~]# docker exec -it b6c786506b21 /bin/bash
- 登录mysql
root@b6c786506b21:/# mysql -u root -p
# 跳过此处密码,直接回车
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.20 MySQL Community Server - GPL
- 重置root密码
mysql> use mysql;
mysql> alter user 'root'@'localhost' IDENTIFIED BY 'Q12345678';
Query OK, 0 rows affected (0.01 sec)
- 退出root用户重新登录
- 移除my.cnf中的配置参数skip-grant-tables。
- 重启mysql docker restart b6c786506b21。
- 进入docker的bash docker exec -it b6c786506b21 /bin/bash。
- 登录root,输入密码。
- 新建用户、建库并授权远程访问
mysql> use mysql;
mysql> create user'test'@'%' identified by 'Q12345678';
mysql> create database nacos_config;
mysql> grant all privileges on nacos_config.* to 'test'@'%' with grant option; --用户授权
mysql> flush privileges;-- 刷新