1. 程式人生 > >MySQL常見問題之——Access denied for user 'root'@'localhost' (using password:YES)解決方法

MySQL常見問題之——Access denied for user 'root'@'localhost' (using password:YES)解決方法

由於我使用的是Windows系統,所以方法也是Windows系統的修改方法:

  1、開始 → 搜尋欄裡面輸入cmd → 右鍵cmd.exe選擇以管理員的身份執行(亦可以在C:\Windows\System32目錄下找到這個cmd.exe,右鍵,以管理員身份執行)

  2、輸入net stop mysql停止MySQL服務

  3、輸入命令列來到mysql的bin目錄下,輸入下列粗體命令

  D:\MySQL\bin>mysqld  --defaults-file="D:\MySQL\my.ini" --console --skip-grant-tables

  等一下,顯示出以下結果說明MySQL啟動:

  170215 22:26:09 [Warning] The syntax '--log' is deprecated and will be removed  inMySQL 7.0. Please use '--general_log'/'--general_log_file' instead.
  170215 22:26:09 [Warning] The syntax '--log_slow_queries' is deprecated and will be removed in MySQL 7.0. Please use '--slow_query_log'/'--  slow_query_log_file' instead.
  170215 22:26:09 [Warning] The syntax '--log' is deprecated and will be removed in MySQL 7.0. Please use '--general_log'/'--general_log_file' instead.
  170215 22:26:09 [Warning] The syntax '--log_slow_queries' is deprecated and will be removed in MySQL 7.0. Please use '--slow_query_log'/'--slow_query_log_file' instead.
  170215 22:26:09 [ERROR] The update log is no longer supported by MySQL in version 5.0 and above. It is replaced by the binary log. Now starting MySQL with --log-bin='' instead.
  170215 22:26:09  InnoDB: Started; log sequence number 0 324221
  170215 22:26:09 [Note] mysqld: ready for connections.Version: '5.1.33-community-log'  socket: ''  port: 3306  MySQL Community Server (GPL)

  4、再以管理員的身份開啟一個cmd.exe,輸入命令列來到mysql的bin目錄下,輸入:mysql -uroot mysql

  5、進入mysql之後,輸入命令列修改密碼:

  mysql>update user set authentication_string=password('123456') where user='root';

  6、重新整理許可權:mysql>flush privileges;

  7、退出mysql:mysql> quit;

  8、關閉MySQL:D:\MySQL\bin>mysqladmin shutdown(出現錯誤,則:mysqladmin -uroot -p shutdown 然後輸入新密碼)

  9、至此修改密碼完成,可以輸入命令列:net start mysql 啟動MySQL服務,mysql -uroot -p ,輸入密碼就可以進入mysql了。

如果再用工具連結資料庫報錯,請看下面步驟:

MySQL錯誤號碼1862:your password has expired

 

執行視窗中進入bin目錄,>mysql -uroot -p123456登入進去,然後執行select * from mysql.users

會有如下資訊:ERROR 1820 (HY000): You must SET PASSWORD before executing this statement

解決:mysql> SET PASSWORD = PASSWORD('123456');

          Query OK, 0 rows affected (0.03 sec)

然後再select * from mysql.users就有結果了。然後再SQLyog就登入進去了。