当前位置:Gxlcms > 数据库问题 > ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

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

时间:2021-07-01 10:21:17 帮助过:23人阅读

centos7.5 登录数据库报错

问题:

[root@db02-52 ~]# 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)停止数据库
[root@db01-51 ~]# /etc/init.d/mysqld stop
2)跳过授权表,跳过网络启动数据库
[root@db01-51 ~]# mysqld_safe --skip-grant-tables --skip-networking &
3)连接数据库
[root@db01-51 ~]#  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
[root@db01-51 ~]# mysqladmin shutdown
[root@db01-51 ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 
6)连接数据库
[root@db01-51 ~]# mysql -uroot -p123
mysql> 

方法二:

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

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

标签:连接数   mysql   授权   ide   interface   comm   com   mysq   inter   

人气教程排行