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


  在安裝好的MySQL服務器上,配置了環境變量之后,發現用mysql無法登錄,報如題的錯誤,實在沒有辦法,決定用安全模式對root用戶修改密碼:

  首先關閉正在運行的MySQL;

  在一個終端窗口運行命令:mysqld_safe --user=mysql --skip-grant-tables --skip-networking&

[root@MySQL ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking&

  運行之后新打開一個終端窗口:

[root@MySQL ~]# mysql -u root mysql
mysql> update mysql.user set authentication_string=password('mysql') where user = 'root'; Query OK, 1 row affected, 1 warning (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye

  以上是5.7版本的修改密碼方式,在5.7中存儲密碼的字段不再是password了,變成了authentication_string,在5.7之前采用以下命令:

mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';

  修改之后登陸成功:

[root@MySQL ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.9-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM