ERROR 1044(42000):拒绝用户''@ localhost'访问数据库'mysql'

时间:2015-05-07 17:13:26

标签: mysql macos command-line terminal

我知道这个问题被多次询问,我读了很多关于此的问题,但我认为我的不同。

我使用版本为10.10.3的Mac和一个终端来执行我的命令。

我正在尝试创建一个本地数据库(我以前做过),但出于某种原因,访问权限一直被拒绝。

这就是我的终端的样子:

iMac-van:mysql 639$ /usr/local/mysql/bin/mysql -v
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.24 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.

Reading history-file /Users/639/.mysql_history
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit;
Writing history-file /Users/639/.mysql_history
Bye
iMac-van:mysql 639$ /usr/local/mysql/bin/mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.24 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> create database wordpress_db;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'wordpress_db'

如您所见,我可以登录mysql,但我没有权限创建数据库。

我尝试登录:

$ /usr/local/mysql/bin/mysql -u root

$ /usr/local/mysql/bin/mysql -u root -p

我没有密码,但我可以在没有密码的情况下输入mysql,但是我无法创建数据库。

选择current_user();返回:

mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| @localhost     |
+----------------+
1 row in set (0,00 sec)

3 个答案:

答案 0 :(得分:1)

尝试使用--skip-grant-tables

启动mysql
mysqld --skip-grant-tables

然后使用mysql命令行连接到没有用户名/密码的mysqld

shell> mysql

然后发出命令

> mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
>        WHERE User='root'; mysql> FLUSH PRIVILEGES;

答案 1 :(得分:0)

首先,尝试以下命令:

sudo dpkg-reconfigure mysql-server-5.5

但将5.5替换为您当前的mysql-server版本,系统将要求您输入新的root密码。

如果这不起作用,请尝试手册中的these instructions

答案 2 :(得分:0)

我有同样的问题。 我所要做的就是退出shell并使用mysql -u root -p再次登录到我的mysql shell中。

然后会提示输入密码。 由于我在设置时没有使用密码,我按下了输入,这就是我的。

我希望这也适合你:)。

相关问题