mysql error 1045 授权_MySQl出现ERROR 1045 (28000): Access denied for user 'root'@'localhost'解决方法...

本是古典 何须时尚 2022-10-27 12:29 368阅读 0赞

描述

使用到是阿里云服务器,系统为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:

删除空账户

#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:

修改密码

#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:

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

发表评论

表情:
评论列表 (有 0 条评论,368人围观)

还没有评论,来说两句吧...

相关阅读