为什么我连接不上mysql?
mysql -u root -ptest101 -h xxx.xxx.xxx.xxx
ERROR 1130 (HY000): Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server
在 my.cnf 我有以下内容
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 0.0.0.0
我也跑了下面...
'UPDATE mysql.user SET Password = PASSWORD('test101') WHERE User = 'root';
FLUSH PRIVILEGES;
我可以使用 mysql -u root -ptest101 在主机上访问,但不能使用 mysql -u root -ptest101 -h xxx.xxx.xxx.xxx
哇...为什么会这样?我是 ubuntj 12.04
mysql> SELECT host FROM mysql.user WHERE User = 'root';
+---------------------------------------------+
| host |
+---------------------------------------------+
| % |
| 127.0.0.1 |
| ::1 | |
| localhost |
+---------------------------------------------+
5 rows in set (0.00 sec)
最佳答案
您的 root
帐户,并且此声明适用于任何帐户,可能只添加了 localhost 访问权限(推荐)。
您可以通过以下方式检查:
SELECT host FROM mysql.user WHERE User = 'root';
如果您只看到 localhost
和 127.0.0.1
的结果,则无法从外部源进行连接。如果您看到其他 IP 地址,但不是您要连接的 IP 地址 - 这也是一种指示。
您需要添加要授予访问权限的每个系统的 IP 地址,然后授予权限:
CREATE USER 'root'@'ip_address' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'ip_address';
如果您看到 %
,那么,还有另一个问题,那就是“任何远程源”。但是,如果您确实希望任何/所有系统都通过 root 连接,请使用 %
通配符来授予访问权限:
CREATE USER 'root'@'%' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
最后,重新加载权限,应该就可以远程访问了:
FLUSH PRIVILEGES;
关于mysql - 错误 1130 (HY000) : Host '' is not allowed to connect to this MySQL server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19101243/