我刚刚通过 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 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'
怎么了?为什么不是 user 'peeja'@'localhost'
?为什么 Just Work™ 不适用于安装用户?这不是 Homebrew 应该设置的方式吗?
还是我做错了什么?
最佳答案
您以匿名用户身份连接 - ''@'localhost'。该用户是在您的服务器上创建的。 而且您还没有创建用户“peeja”@“localhost”。默认情况下,MySQL 连接使用匿名帐户。
因此,以 root 身份连接并创建用户 -
CREATE USER 'peeja'@'localhost';
然后授予您需要的权限并以 'peeja'@'localhost' 身份重新连接。
关于mysql - 当 MySQL 告诉我 "Access Denied"时,为什么它认为我的用户名是 '' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12515368/