docker exec -it 容器Id bash
mysql -u root -p
输入密码报错:
Access denied for user 'mysql'@'localhost' (using password: YES)
退出容器,找到挂载的配置文件目录,在
[mysqld]
user=mysql
character-set-server=utf8
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log = /var/log/mysqld_common.log
log-error = /var/log/mysqld_err.log
log-bin = /var/log/mysqld_bin.bin
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
#skip-grant-tables
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
#--skip-host-cache
#--skip-name-resolve
[mysqld] 下任意行加入skip-grant-tables
重起容器
docker restart 容器Id
进入容器,连接mysql;
use mysql
更新root密码
select user,authentication_string from user;
update user set authentication_string='' where user='root';
注释掉my.cnf 文件中的 skip-grant-tables
再次重起容器,进入容器,连接mysql
alter user'root'@'%' IDENTIFIED BY '123456';
#alter user'root'@'localhost' IDENTIFIED BY '123456';
flush privileges;
发现用mysql客户端navcat连接,报 连不上
MYSQL 8.0内新增加mysql_native_password函数,通过更改这个函数密码来进行远程连接。更改ROOT用户的native_password密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY'Mysql@123';
执行完成。既可以连接了。
查看变量值:
SHOW VARIABLES LIKE 'lower%';
参考地址:https://blog.csdn.net/zhldt2008/article/details/81127145