且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用php通过本地服务器连接托管服务器数据库?

更新时间:2023-02-04 07:46:19

连接远程数据库需要三件事:

There a three things you need to connect to a remote database:

  • 端口 3306 在防火墙上打开.服务器和客户端的防火墙必须打开 3306 端口!
  • 在my.cnf中bind-address = 0.0.0.0让mysql绑定所有接口
  • 在数据库中有足够的权限以允许远程连接

几乎所有托管公司都关闭了防火墙上的 3306 端口,并且不允许直接远程访问.即使他们这样做,您也不会获得连接到数据库的权限.

Virtual all hosting companies close port 3306 on the firewall, and do not allow direct remote access. And even if they do, you won't get privileges to connect to a database.

仅当远程数据库在您的 LAN 中,或者您正在使用具有 root 访问权限的 VPS 时,您才能进行配置以建立远程连接.

Only if the remote database is in your LAN, or you are using a VPS with root access you can configure things to make a remote connection.