乐趣区

关于mysql:Access-denied-for-user-rootlocalhost-using-password-YES

Docker 运行 Mysql 在 Mysql workbench 无奈连贯

docker run –name mysql-server -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=bei!123 -d mysql

Docker MySql Error:
Access denied for user 'root'@'localhost' (using password: YES)

解决方案:

  1. sudo mkdir /usr/local/mysql
  2. sudo mkdir /usr/local/mysql/data
  3. sudo mkdir /usr/local/mysql/conf.d
  4. docker run –name mysql-server -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=bei!123 -d mysql
  5. touch /usr/local/mysql/conf.d/my.cnf
  6. sudo gedit /usr/local/mysql/conf.d/my.cnf, and type in below:

    [mysqld]
    skip-grant-tables
  7. docker restart [mysql container id]
  8. docker exec -it [mysql container id] bash
  9. mysql -uroot -p
  10. grant all privileges on . to ‘root’@’%’ identified by ‘bei!123’;
  11. select user,authentication_string,host from user;
  12. update user set authentication_string=” where user=’root’;
  13. flush privileges;
  14. quit mysql ctrl d d
  15. sudo gedit /usr/local/mysql/conf.d/my.cnf
  16. delete ‘skip-grant-tables’
  17. docker restart [mysql container id]
  18. docker exec -it [mysql container id] bash
  19. mysql -uroot -p (明码是回车)
  20. use mysql;
  21. alter user ‘root’@’localhost’ IDENTIFIED BY ‘bei!123’;
  22. alter user ‘root’@’%’ IDENTIFIED BY ‘beya!123’;
  23. flush privileges;
  24. GRANT all ON . TO ‘root’@’%’ IDENTIFIED BY ‘bei!123’;
  25. flush privileges;

尝试过,可行。

退出移动版