mysql报错:Access denied for user ‘root‘@‘localhost‘ (using password YES)

mysql报错:Access denied for user ‘root’@‘localhost’ (using password: YES)

# 报错如下:
[root@client ~]# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@client ~]# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES

在这里插入图片描述

解决办法:

# root密码错误,重置root用户密码
[root@client ~]# whereis my.cnf
my: /etc/my.cnf
# 加入这句skip-grant-tables跳过密码验证
[root@client ~]# vim /etc/my.cnf
  1 [mysqld]
  2 skip-grant-tables
[root@client ~]# systemctl restart mariadb.service 
[root@client ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use mysql             # 无需验证即可以mysql用户登录数据库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> select host,user,password from user;
+-----------+--------+-------------------------------------------+
| host      | user   | password                                  |
+-----------+--------+-------------------------------------------+
| localhost | root   | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| client    | root   | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| 127.0.0.1 | root   | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| ::1       | root   | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost |        |                                           |
| client    |        |                                           |
| localhost | zabbix | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+--------+-------------------------------------------+
# 修改密码,密码存放在user表中
MariaDB [mysql]> update user set password=password("123456") where user="root";
MariaDB [mysql]> commit;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> exit
Bye


[root@client ~]# vim /etc/my.cnf
删除这句  skip-grant-tables
[root@client ~]# systemctl restart mariadb.service 
[root@client ~]# mysql -uroot -p        # 可以正常登录了。
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 
p. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

猜你喜欢

转载自blog.csdn.net/weixin_36522099/article/details/108087938