Shell

root 使用者無法訪問 MySql

  • November 17, 2013

我有一個本地 MySql 伺服器。它已啟動,因為我可以使用本地使用者訪問它,例如

$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 66
Server version: 5.5.34-0ubuntu0.13.04.1 (Ubuntu)

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

很好,但是當我嘗試使用 root 時,我不斷得到這個:

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

這是什麼意思,我該如何解決?

編輯

這也不起作用(執行後sudo mysql_install_db):

$ /usr/bin/mysqladmin -u root password 'MyPass'
/usr/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

嘗試使用

mysql -u root -p

提示密碼。

如果這不起作用,那麼也許可以參考https://stackoverflow.com/questions/11760177/access-denied-for-root-user-in-mysql-command-line

引用自:https://unix.stackexchange.com/questions/101461