Docker安装mysql报错 ERROR 1045 (28000): Access denied for user

一进入mysql报错:1045 (28000)错误:

”Access denied for user ‘root’@’localhost’ (using password: YES)”

启动容器:

docker run --name mysql5.6 -p 3306:3306 -v /usr/local/mysql/data:/var/lib/mysql -v /usr/local/mysql/conf.d:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6

处理该错误的做法
1.在 /usr/local/mysql/conf.d目录下增加文件: my.cnf,并编辑

[mysqld]
skip-grant-tables

2.重启mysql

docker restart mysql5.6

3.进入docker容器内部

docker exec -it mysql5.6 bash

4.登录mysql

mysql -uroot -p

5.设置root密码为空,注意root密码是加密的

use mysql;

select user,authentication_string,host from user;

更新为空

update user set authentication_string='' where user='root';

flush privileges;

6 退出mysql,把第一步的skip-grant-tables注释。再重启mysql
7 使用 root用户,登录;
8修改root密码

alter user 'root'@'localhost' IDENTIFIED BY 'rootroot';

alter user 'root'@'%' IDENTIFIED BY 'rootroot';

flush privileges;

9.附加授权

GRANT all ON . TO 'root'@'%' IDENTIFIED BY 'rootroot' ;

flush privileges;

你可能感兴趣的:(Web前后端)