php 使用端口 3307 连接到 MySql
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12411171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connecting to MySql using port 3307
提问by Bob Swaggerty
I am trying to connect to MySql database remotely using the following script on port 3307
我正在尝试使用端口 3307 上的以下脚本远程连接到 MySql 数据库
$username="user";
$password="pass";
$database="db";
mysql_connect('ccline.dyndns.info:3307',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
but unable to connect. I was using this same script on a db using 3306. What am I missing??
但无法连接。我在使用 3306 的数据库上使用相同的脚本。我错过了什么?
回答by JvdBerg
There a three things you need to connect to a remote database:
连接到远程数据库需要三件事:
- port 3306 open on the firewalls. Firewalls in server and client must open port 3306!
- in my.cnf bind-address = 0.0.0.0 to let mysql bind to all interfaces
- sufficient privileges in the database to allow remote connections
- 在防火墙上打开端口 3306。服务器端和客户端的防火墙必须开放3306端口!
- 在 my.cnf bind-address = 0.0.0.0 让mysql绑定到所有接口
- 数据库中有足够的权限以允许远程连接
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.
虚拟所有托管公司都关闭了防火墙上的 3306 端口,并且不允许直接远程访问。即使他们这样做,您也不会获得连接到数据库的权限。
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.
只有当远程数据库在您的 LAN 中,或者您使用具有 root 访问权限的 VPS 时,您才能配置一些东西来建立远程连接。
回答by donald123
First: You miss to use the mysqli_* functions instead of the mysql_* function For more informations take a look here
第一:您错过了使用 mysqli_* 函数而不是 mysql_* 函数有关更多信息,请查看此处
To your question: I bet, on your mysql_server ccline.dyndns.infothe port 3306 / 3307 is not open ... or the server is configurated not to listen on request wich are not equal localhost
对于您的问题:我敢打赌,在您的 mysql_server ccline.dyndns.info 上,端口 3306 / 3307 未打开……或者服务器配置为不侦听请求,但不等于localhost
So if you use the php-script on the same machine as the mysql server, connect by localhost:3307.....
所以如果你在mysql服务器所在的机器上使用php-script,通过localhost:3307连接.....

