为什么哦为什么我不能连接到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
Run Code Online (Sandbox Code Playgroud)
在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
Run Code Online (Sandbox Code Playgroud)
我也跑了以下......
'UPDATE mysql.user SET Password = PASSWORD('test101') WHERE User = 'root';
FLUSH PRIVILEGES;
Run Code Online (Sandbox Code Playgroud)
我可以使用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)
Run Code Online (Sandbox Code Playgroud)
new*_*rey 262
您的root帐户和此声明适用于任何帐户,可能只是添加了localhost访问权限(建议使用).
您可以通过以下方式检查:
SELECT host FROM mysql.user WHERE User = 'root';
Run Code Online (Sandbox Code Playgroud)
如果您只看到带有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';
Run Code Online (Sandbox Code Playgroud)
如果你看到%,那么完全是另一个问题,因为那是"任何远程源".但是,如果您确实希望任何/所有系统通过root连接,请使用%通配符授予访问权限:
CREATE USER 'root'@'%' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
Run Code Online (Sandbox Code Playgroud)
最后,重新加载权限,您应该能够远程访问:
FLUSH PRIVILEGES;
Run Code Online (Sandbox Code Playgroud)
小智 17
以下两个步骤对我来说非常合适:
注释掉文件中的绑定地址/etc/mysql/my.cnf:
#bind-address = 127.0.0.1
在phpMyAdmin中运行以下查询:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'; FLUSH PRIVILEGES;
小智 9
$mysql -u root --host=127.0.0.1 -p
mysql>use mysql
mysql>GRANT ALL ON *.* to root@'%' IDENTIFIED BY 'redhat@123';
mysql>FLUSH PRIVILEGES;
mysql> SELECT host FROM mysql.user WHERE User = 'root';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
266124 次 |
| 最近记录: |