我已经在我的本地机器上安装了MySQL Community Edition 5.5,我想允许远程连接,这样我就可以从外部源连接。
我该怎么做呢?
我已经在我的本地机器上安装了MySQL Community Edition 5.5,我想允许远程连接,这样我就可以从外部源连接。
我该怎么做呢?
当前回答
启用远程根访问可能是危险的。如果您要设置具有更严格权限的用户帐户,则更可取。以下三个步骤可以做到这一点。
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)
其他回答
启用远程根访问可能是危险的。如果您要设置具有更严格权限的用户帐户,则更可取。以下三个步骤可以做到这一点。
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)
如果你从brew安装MySQL,默认情况下它只监听本地接口。要解决这个问题,您需要编辑/usr/local/etc/my.cnf并将绑定地址从127.0.0.1更改为*。
然后运行brew services重启mysql。
如果您的MySQL服务器进程正在监听127.0.0.1或::1,那么您将无法远程连接。如果您在/etc/my.cnf中设置了绑定地址,这可能是问题的根源。
您还必须为非本地主机用户添加特权。
MySQL 8不再允许您使用GRANT命令创建用户。您需要首先创建用户。
CREATE USER 'root'@'%' IDENTIFIED BY 'PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
检查远程服务器是否允许通配符访问端口3306:
sudo lsof -i -P -n | grep监听
不应该是这样的:
mysqld 23083 mysql 21u IPv4 145900142 0t0 TCP 127.0.0.1:3306(听)
在这种情况下,我们需要更新/etc/mysql/mysql.conf.d/mysqld.cnf或/etc/mysql/mariadb.conf.d/50-server.cnf:
Bind-address = 127.0.0.1——> 0.0.0.0
然后重新启动mysql "sudo service mysql restart"
为了从客户端测试mySQL连接:
Nc -vz <host_address> 3306