• MySQl出现ERROR 1045 (28000): Access denied for user 'root'@'localhost'解决方法


    描述

    使用到是阿里云服务器,系统为cent Os,给某个账户授权之后,root的账户就登录不进去了,原本root账户设置好了远程连接的权限了,网上搜索了一大堆,终于自己摸索得到了几个方法

    产生原因

    • root账户不能远程连接
    • mysql中存在空账户
    • root账户密码错误(可能是密码输错,因为linux输入密码什么都不显示..)

    解决方法

    以下的三种方法,其实都是要进入mysql的安全模式中,对默认的user表进行修改

    设置root账户为远程

    #1.停止mysql数据库
    service mysql stop
     
    #2.执行如下命令
    mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
     
    #3.使用root登录mysql数据库
    mysql -u root mysql
     
    4.修改root账户可以远程连接
    mysql> update user set host='%' where user='root' and host='localhost';
    
    # mysql5.7MySQL请采用如下SQL:
    mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
     
    #5.刷新权限(必须,防止mysql的缓存影响)
    mysql> FLUSH PRIVILEGES;
     
    #6.退出mysql
    mysql> quit
     
    #7.重启mysql
    service mysql restart
     
    #8.使用root用户重新登录mysql
    mysql -uroot -p 
    Enter password: <输入新设的密码newpassword>
    

    删除空账户

    #1.停止mysql数据库
    service mysql stop
     
    #2.执行如下命令
    mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
     
    #3.使用root登录mysql数据库
    mysql -u root mysql
     
    4.删除空用户
    mysql> mysql> delete from user where user='';
    
    # mysql5.7MySQL请采用如下SQL:
    mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
     
    #5.刷新权限(必须,防止mysql的缓存影响)
    mysql> FLUSH PRIVILEGES;
     
    #6.退出mysql
    mysql> quit
     
    #7.重启mysql
    service mysql restart
     
    #8.使用root用户重新登录mysql
    mysql -uroot -p 
    Enter password: <输入新设的密码newpassword>
    
    

    修改密码

    #1.停止mysql数据库
    service mysql stop
     
    #2.执行如下命令
    mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
     
    #3.使用root登录mysql数据库
    mysql -u root mysql
     
    4.修改密码
    mysql> update user ser password = password('newpassword') where user = 'root';
    
    # mysql5.7以上,请采用如下SQL:
    mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
     
    #5.刷新权限(必须,防止mysql的缓存影响)
    mysql> FLUSH PRIVILEGES;
     
    #6.退出mysql
    mysql> quit
     
    #7.重启mysql
    service mysql restart
     
    #8.使用root用户重新登录mysql
    mysql -uroot -p 
    Enter password: <输入新设的密码newpassword>
    
    

    参考链接:
    百度知道 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
    解决 ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

    PS:欢迎评论,提出错误,补充解决方法

  • 相关阅读:
    PHP
    PHP
    密码修改机制
    PHP
    PHP
    PHP
    PHP
    Java并发编程:进程和线程的由来(转)
    Java获取文件大小的正确方法(转)
    J2EE开发中常用的缓存策略
  • 原文地址:https://www.cnblogs.com/stars-one/p/12253359.html
Copyright © 2020-2023  润新知