'Access denied for user 'root'@'localhost' (using password: NO)'

我们使用MySQL时,有时会忘记密码,可以通过如下方式将密码进行重置。

[root@localhost ~]# /etc/init.d/mysqld stop    停止MySQL服务
Stopping mysqld:                                           [  OK  ]

[root@localhost ~]# mysqld_safe --skip-grant-tables &    使用安全模式进入
[1] 13694
[root@localhost ~]# 180316 00:57:08 mysqld_safe Logging to '/var/log/mysqld.log'.
180316 00:57:08 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

mysql    输入mysql 命令连接数据库


Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> update user set password = password("123456") where user = 'root';  重置root密码
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

重启mysql服务器,使用新密码就能登录了。

你可能感兴趣的:('Access denied for user 'root'@'localhost' (using password: NO)')