root 用户无法访问 MySql

root 用户无法访问 MySql

我有一个本地 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)'

答案1

尝试使用

mysql -u root -p

出现密码提示。

如果这不起作用,那么也许可以参考https://stackoverflow.com/questions/11760177/access-denied-for-root-user-in-mysql-command-line

相关内容