我已经在我的本地机器上安装了MySQL Community Edition 5.5,我想允许远程连接,这样我就可以从外部源连接。

我该怎么做呢?


当前回答

对于需要它的人,检查防火墙端口3306是否也打开了,如果您的防火墙服务正在运行。

其他回答

在我的情况下,我试图连接到一个远程mysql服务器在cent操作系统。在经历了许多解决方案(授予所有特权,删除ip绑定,启用网络)后,问题仍然没有得到解决。

事实证明,在寻找各种解决方案时,我遇到了iptables,这让我意识到mysql端口3306不接受连接。

下面是关于我如何检查和解决这个问题的一个小说明。

检查端口是否接受连接:

telnet (mysql server ip) [portNo]

添加ip表规则,允许端口上的连接:

iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT

不建议在生产环境中这样做,但如果您的iptables没有正确配置,添加规则可能仍然不能解决问题。在这种情况下,应该做以下工作:

service iptables stop

希望这能有所帮助。

对于OS X用户,请注意bind-address参数通常是在launchd plist中设置的,而不是在my.ini文件中。所以在我的情况下,我删除了<string>——bind-address=127.0.0.1</string>从/Library/LaunchDaemons/homebrew.mx .mariadb.plist。

这篇如何在局域网上安装MySQL服务器的博客将有助于从头开始安装MySQL

启用远程根访问可能是危险的。如果您要设置具有更严格权限的用户帐户,则更可取。以下三个步骤可以做到这一点。

Ensure that the line starting with bind-address ... is at least commented out in your my.ini or my.cnf file. If it doesn't exist, move on. You can find this file in C:\ProgramData\MySQL\MySQL Server 8.0 on Windows. Afterwards, check that the user account you are establishing the connection with does not have localhost in the Limit to Hosts Matching field. While it isn't recommended, you can instead put % in that field for testing purposes. You can do this by opening a local connection to the server with MySQL Workbench, then going to Server>Users and Privileges from the menu bar and finding the user account you want to connect with.

“限制主机匹配”字段是不允许您连接非本地。也就是说,它将接受的连接限制为一个IP地址模式。理想情况下,您应该从静态IP地址或子网访问MySQL服务器,这样您就可以尽可能地限制。

显然,您的防火墙应该允许MySQL服务器应用程序通过您想要的端口进行通信。您和服务器之间的物理网络设备应该允许在您想要连接的端口上进行通信。(通常端口为3306)

远程登录的所有流程。默认关闭远程登录。你需要手动打开所有ip..来访问所有ip

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';

特定的Ip

GRANT ALL PRIVILEGES ON *.* TO 'root'@'your_desire_ip' IDENTIFIED BY 'password';

然后

flush privileges;

您可以检查您的用户主机和密码

SELECT host,user,authentication_string FROM mysql.user;

现在你的责任就是改变这一切

bind-address = 127.0.0.1

你可以找到这个

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

如果你在那里找不到这个,那就试试这个

sudo nano /etc/mysql/my.cnf

在此评论

#bind-address = 127.0.0.1

然后重新启动Mysql

sudo service mysql restart

现在享受远程登录