Access denied for user 'root'@'localhost' (using password: YES)解决方案

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bicongming/article/details/78581694

这个问题困扰了我好几次,前几次出现这个问题,第二天莫名奇妙的就好了,现在我终于忍不了了,总的来说是权限问题,好了废话不多说,直接上解决方案:

  1. 在mysql的配置文件中添加skip-grant-tables(跳过密码直接进入mysql)
  2. 重启mysql:service mysqld restart
  3. 免密码进入mysql:mysql -uroot -p
    password:(直接回车)
  4. 给所有用户添加权限
    mysql> set global read_only=0;//(关掉新主库的只读属性)
    mysql>flush privileges;
    mysql>set global read_only=1;//(读写属性)
    mysql>flush privileges;
    mysql>grant all privileges on *.* to ‘root’@‘%’ identified by ‘root’ with grant option;(多次实验发现这里有个坑,是csdn挖的,就是符号问题,如果报错,最好在命令行手动输入)
    关键词解释:
    ‘root’@‘%’:是用户
    ‘root’:是密码

  5. 在mysql的配置文件中屏蔽掉skip-grant-tables

  6. 重启mysql:service mysqld restart

猜你喜欢

转载自blog.csdn.net/bicongming/article/details/78581694