【发布时间】:2014-04-04 18:47:59
【问题描述】:
我真的想不通。在某个用户下,我可以从机器 B 连接到机器 A 上的 MySQL 数据库,但是我无法从机器 A 本身本地连接或从 PHP 连接。
为了说明,我在机器 A 上创建了一个数据库 MYTEST。然后我创建一个用户 MYTEST 并授予 MYTEST 上的所有权限:
GRANT ALL PRIVILEGES ON MYTEST.* TO 'MYTEST'@'%' IDENTIFIED BY 'mypass';
FLUSH PRIVILEGES;
我以 root 身份进行了这些操作,我可以从任何地方毫无问题地进行连接。结果:
然后,我尝试从另一台机器 B 连接:
ubuntu@ip-*-*-2-153:~$ mysql -u MYTEST -p -h *.*.*.174
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 84
Server version: 5.5.32-0ubuntu7 (Ubuntu)
Copyright (c) 2000, 2013, 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>
这些看起来都不错。现在我回到机器 A 并这样做:
root@wangboyang:~# mysql -u MYTEST -p
Enter password:
ERROR 1045 (28000): Access denied for user 'MYTEST'@'localhost' (using password:
YES)
root@wangboyang:~#
而我能够以 root 身份连接:
root@wangboyang:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
最终,我需要从 PHP 进行连接。它也不起作用:
php > $con = mysqli_connect('128.199.253.174', 'MYTEST', 'mypass');
PHP Warning: mysqli_connect(): (28000/1045): Access denied for user 'MYTEST'@'w
angboyang.com' (using password: YES) in php shell code on line 1
我必须使用root:
php > $con = mysqli_connect('128.199.253.174', 'root', 'somepasswordhere');
php >
然后我尝试了一些激进的方法。我将所有全局权限授予 MYTEST,但所有结果都保持不变。请问有人有什么想法吗?真的很感激。
注意:
我确定密码正确。为了确认这一点,我使用了与 root 相同的密码,并将哈希值进行了比较。我可以使用root连接。所以密码是正确的。
两台机器都是Ubuntu 13.10。
我尝试在所有这些步骤之间刷新权限并重新启动 mysql 服务器,但无济于事。
【问题讨论】:
-
我的托管公司只允许某些ip addy连接到数据库,我必须进去列出它们。也许你的也一样。
-
我的机器 A 在 Digitalocean 上,机器 B 在亚马逊上。似乎并非如此。此外我正在尝试使用 localhost 进行连接,这应该是允许的第一件事......
标签: php mysql mysqli remote-access privileges