ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)(

Posted 吕涵之的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)(相关的知识,希望对你有一定的参考价值。

centos7.5 登录数据库报错

问题:

[[email protected] ~]# mysql -uroot -p123
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

原因:数据库中的root用户被误删除

解决方法:

方法一:

1)停止数据库
[[email protected] ~]# /etc/init.d/mysqld stop
2)跳过授权表,跳过网络启动数据库
[[email protected] ~]# mysqld_safe --skip-grant-tables --skip-networking &
3)连接数据库
[[email protected] ~]#  mysql
4)插入新root用户
insert into mysql.user values ('localhost','root',PASSWORD('123'),'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','','N');
5)重启MySQL
[[email protected] ~]# mysqladmin shutdown
[[email protected] ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 
6)连接数据库
[[email protected] ~]# mysql -uroot -p123
mysql> 

方法二:

1)停止数据库
[[email protected] ~]# /etc/init.d/mysqld stop
2)跳过授权表,跳过网络启动数据库
[[email protected] ~]# mysqld_safe --skip-grant-tables --skip-networking &
3)连接数据库
[[email protected] ~]# mysql
4)刷新授权表
mysql> flush privileges;
5)创建root超级用户
mysql> grant all on *.* to [email protected]'localhost' identified by '123' with grant option;
6)重启MySQL
[[email protected] ~]# mysqladmin -uroot -p123 shutdown
[[email protected] ~]# /etc/init.d/mysqld start
7)登录数据库
[[email protected] ~]# mysql -uroot -p123
mysql>

以上是关于ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)(的主要内容,如果未能解决你的问题,请参考以下文章

mysql ERROR 1045 (28000): 错误解决办法

mysql ERROR 1045 (28000): 错误解决办法

mysql ERROR 1045 (28000): 错误解决办法

mysql登录时,ERROR 1045 (28000): 错误解决办法

用grant命令为用户赋权限以后,登录时,出现:ERROR 1045 (28000)

ERROR 1045 (28000): Access denied for user ‘root‘@