很多时候我们面临如下问题,当我们尝试从远程客户端连接MySQL服务器时,MySQL服务器不允许我们连接。
# mysql -h 192.168.1.10 -u root -p
Enter password:
[Output]
ERROR 1130 (HY000): Host '192.168.1.12' is not allowed to connect to this MySQL server
这个问题是因为,远程客户端没有权限来连接MySQL服务器。默认情况下MySQL服务器不允许任何远程客户端连接。
允许MySQL客户端连接:
要允许客户端连接MySQL服务器。使用ssh登录到远程MySQL服务器,然后登录到本地的MySQL服务器。现在,使用下面的命令来允许远程客户端。例如,如果远程客户端的ip是 192.168.1.12并试图通过MySQL的root帐户连接。
[下面的命令需要在MySQL服务器上运行]
# mysql -u root -p
Enter password:
mysql> GRANT ALL ON *.* to root@'192.168.1.12' IDENTIFIED BY 'new-password';
mysql> FLUSH PRIVILEGES;
mysql> quit
您已成功的在MySQL服务器上创建了可以从指定客户端连接的一个新帐户。
让我们试着从客户端连接服务器 。
# mysql -h 192.168.1.10 -u root -p
[Sample Output]
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 27
Server version: 5.1.69 Source distribution
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>