简体   繁体   English

无法连接远程MYSQL服务器

[英]Unable to Connect remote MYSQL server

I have given all privileges to the root user, but I am unable to access remotely. 我已将所有特权授予root用户,但无法远程访问。 I have given permission in firewall to access the port 3306 but I am unable to connect. 我已在防火墙中授予访问端口3306的权限,但无法连接。

I am getting the error: your connection attempt failed for user 'root' from your host to server xxx.xxx.x.xx:3306 我收到错误消息: your connection attempt failed for user 'root' from your host to server xxx.xxx.x.xx:3306

Look inside the my.cnf file for the bind address directive. 在my.cnf文件中查找绑定地址指令。 This will tell mysql what IP to get access from. 这将告诉mysql从哪个IP访问。

# 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

0.0.0.0 is there only to provide the most generic answer but for security reasons should be replaced by a specific address Please note that the safe way to do this is to specify only some specific IP and not use a wildcard for that. 0.0.0.0仅用于提供最通用的答案,但出于安全原因,应使用特定的地址代替。请注意,这样做的安全方法是仅指定某些特定的IP,而不使用通配符。 This way only trusted clients will be able to login. 这样,只有受信任的客户端才能登录。

NOTE: check if you granted to the user that will connect the permission on that IP (or from wildcard). 注意:检查是否已授予将连接该IP权限(或通配符)的用户的权限。 If not you have to run these: 如果不是,则必须运行以下命令:

GRANT ALL privileges ON testDB.* TO 'testUSER'@'IP_Address' IDENTIFIED BY 'testPassword';
FLUSH PRIVILEGES;

Adapt these commands to your environment 使这些命令适应您的环境

Writing up this answer as you said my comment was the answer you needed. 如您所说,写下您的答案就是您需要的答案。

Your root user is probably 'root'@'localhost' which means it will only accept logins from localhost. 您的root用户可能是'root'@'localhost' ,这意味着它将仅接受来自localhost的登录。 Create 'root'@'%' to allow logins from anywhere. 创建'root'@'%'以允许从任何地方登录。

I recommend not using % unless you really lock down the permissions. 我建议不要使用%除非您确实锁定了权限。 Even better though, use 'root'@'YOUR IP HERE' ! 更好的是,使用'root'@'YOUR IP HERE'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM