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

OS: Ubuntu 6.06.1 Dapper Drake (2.6.15-51-amd64-server)
MySQL: 5.0.22

第一次安裝 MySQL 就遇到了奇怪的問題,不知道是不是自己沒搞清楚?!

症狀:

       使用 synaptic 安裝 mysql 後,呼叫 mysql_install_db 初始化後,想透過 SHELL> mysql -u root 登入,建立密碼,卻出現 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO),即使想透過 mysql -u root -p ,強制輸入密碼,仍一樣出錯,只是錯誤變成 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

解決方法[3]:

  1. 先關閉 mysql daemon
  2. 以 --skip-grant-tables 喚起 mysql daemon ,如:mysqld --skip-grant-tables
  3. 這時應當可透過以下指令登入:mysql -u root mysql
  4. 利用 mysql 指令修改使用者密碼。
  5. mysql> UPDATE user SET Password=PASSWORD('your_new_password') where USER='root';
    mysql> FLUSH PRIVILEGES;
  6. 關閉 mysql daemon 後,再正常啟動。
  7. 似乎之後新增 database user 也需透過這個方法。

參考資料:

  1. MySQL Manual 2.10.3. Securing the Initial MySQL Accounts http://dev.mysql.com/doc/refman/4.1/en/default-privileges.html
  2. 鳥哥的 Linux 私房菜 http://linux.vbird.org/
  3. MySQL Forum http://forums.mysql.com/read.php?11,34014,46593#msg-46593

沒有留言:

Windows + Visual Studio + VSCode + CMake 的疑難雜症

Environment Windows 10 Visual Studio 2019 CMake 3.27.7 VSCode VSCode CMake Tools 1. CMAKE_BUILD_TYPE 是空的 參考一下 這篇 的處理。 大致上因為 Visual...