ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'db',怎么解决?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (128)

我想开始用MySQL编写查询。

show grants显示:

+--------------------------------------+
| Grants for @localhost                |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+

我没有任何用户ID,但是当我想要成为一个用户时,我没有特权,而且我也不知道当我没有一个用户的时候,我也不知道如何获得特权!

mysql> CREATE USER 'parsa'@'localhost' IDENTIFIED BY 'parsa';
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER pr
ivilege(s) for this operation

我试着以root登录:

mysql> mysql -u root -p;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'mysql
 -u root -p' at line 1
mysql> mysql -u root -p root;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'mysql
 -u root -p root' at line 1
提问于
用户回答回答于

应该mysql -u root -p在bash中,而不是在MySQL命令行中。如果在MySQL中,可以通过键入exit

用户回答回答于

可能需要为MySQL数据库设置一个根帐户:

在终端类型中:

mysqladmin -u root password 'root password goes here'

然后调用MySQL客户端:

mysql -h localhost -u root -p

扫码关注云+社区