首先让我提一下,我已经看了很多建议的问题,但没有找到相关的答案。这就是我正在做的。
我连接到Amazon EC2实例。我可以用这个命令登录MySQL根目录:
mysql -u root -p
然后我用host %创建了一个新的用户帐单
CREATE USER 'bill'@'%' IDENTIFIED BY 'passpass';
授予用户bill的所有权限:
grant all privileges on *.* to 'bill'@'%' with grant option;
然后我退出root用户,尝试用bill登录:
mysql -u bill -p
输入正确的密码并得到以下错误:
错误1045(28000):用户“账单”@“localhost”(使用密码:YES)的访问被拒绝
我遇到了同样的错误。失败的设置如下:
define("HOSTNAME", "localhost");
define("HOSTUSER", "van");
define("HOSTPASS", "helsing");
define("DBNAME", "crossbow");
$connection = mysqli_connect(HOSTNAME, HOSTUSER, HOSTPASS);
下面编辑的设置是让它工作的一个。注意到区别了吗?
define('HOSTNAME', 'localhost');
define('HOSTUSER', 'van');
define('HOSTPASS', 'helsing');
define('DBNAME', 'crossbow');
$connection = mysqli_connect(HOSTNAME, HOSTUSER, HOSTPASS);
区别在于双引号。与Java相比,它们在PHP中似乎相当重要,它们在转义字符、设置url以及现在向函数传递参数时都有影响。它们更漂亮(我知道),但总是尽可能多地使用单引号,如果必要的话,可以在其中嵌套双引号。
当我在Linux机器上而不是Windows环境上测试应用程序时,出现了这个错误。
这是以下两者之间的区别:
CREATE USER 'bill'@'%' IDENTIFIED BY 'passpass';
and
CREATE USER 'bill'@'localhost' IDENTIFIED BY 'passpass';
检查:
mysql> select user,host from mysql.user;
+---------------+----------------------------+
| user | host |
+---------------+----------------------------+
| bill | % | <=== created by first
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
| bill | localhost | <=== created by second
+---------------+----------------------------+
命令
mysql -u bill -p
隐式访问'bill'@'localhost',而不是'bill'@'%'。
“bill”@“localhost”没有权限
你会得到错误:
ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)
解决问题:
CREATE USER 'bill'@'localhost' IDENTIFIED BY 'passpass';
grant all privileges on . to 'bill'@'localhost' with grant option;
I discovered yet another case that appears on the surface to be an edge case; I can export to the file system, via SELECT INTO .. OUTFILE as root, but not as regular user. While this may be a matter of permissions, I've looked at that, and see nothing especially obvious. All I can say is that executing the query as a regular user who has all permissions on the data base in question returns the access denied error that led me to this topic. When I found the transcript of a successful use of SELECT INTO … OUTFILE in an old project, I noticed that I was logged in as root. Sure enough, when I logged in as root, the query ran as expected.
我希望你在mysql中删除debian-sys- maintenance用户没有造成更大的损害
让你的mysql守护进程正常运行。启动mysql客户端,如下所示
mysql -u debian-sys-maint -p
在另一个终端,cat /etc/mysql/debian.cnf文件。该文件包含密码;当提示输入密码时,粘贴该密码。
http://ubuntuforums.org/showthread.php?t=1836919