当MySQL告诉我;“访问被拒绝”;,为什么它认为我的用户名是'';?

当MySQL告诉我;“访问被拒绝”;,为什么它认为我的用户名是'';?,mysql,homebrew,Mysql,Homebrew,我刚刚通过自制在OS X Lion上安装了MySQL,并遵循了安装后的说明。现在我需要建立一个数据库: $ mysql -u peeja Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 22 Server version: 5.5.25a Source distribution Copyright (c) 2000, 2011, Oracle and/or its aff

我刚刚通过自制在OS X Lion上安装了MySQL,并遵循了安装后的说明。现在我需要建立一个数据库:

$ mysql -u peeja
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.5.25a Source distribution

Copyright (c) 2000, 2011, 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 `new_db` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'new_db'
用户'@'localhost'
怎么了?为什么不
用户'peeja'@'localhost'
?为什么这不管用呢™ 对于安装用户?这不就是自制软件的设置方式吗


还是我做错了什么?

没有用户
peeja
没有密码,所以它会将您记录为匿名用户。如果该用户存在,则登录为:

mysql -u peeja -p mypassword


您以匿名用户身份连接-'@'localhost'。此用户是在您的服务器上创建的。 您还没有创建用户“peeja”@“localhost”。默认情况下,MySQL connect使用匿名帐户

因此,以root用户身份连接并创建用户-

CREATE USER 'peeja'@'localhost';

然后授予您所需的权限并以“peeja”@“localhost”身份重新连接。

不知道,但可能不使用空格:
mysql-upeeja
除了您收到的答案之外,删除匿名用户可能是个好主意。我甚至不知道有匿名用户。:)哦!说明中说服务器将以我的用户身份运行,而不是自动创建一个名为我的用户(Postgres公式就是这样做的)。谢谢你的解释;我没有意识到它会退回到一个匿名用户。
CREATE USER 'peeja'@'localhost';