简体   繁体   中英

mysql_connect to Remote Server from local machine

So I'm trying develop on my local machine, while using one database on my remote server.

To do this I've tried changing the myql_connect line.

from

$con = mysql_connect("localhost", "username", "pw");

to

$con = mysql_connect("mydomain.com:2082", "username", "pw");

and now I'm getting the following errors

Warning: mysql_connect() [function.mysql-connect]: MySQL server has
gone away in C:\\xampp\\htdocs\\posts\\index.php on line 27 Warning:
mysql_connect() [function.mysql-connect]: Error while reading greeting
packet. PID=5092 in C:\\xampp\\htdocs\\posts\\index.php on line 27
Warning: mysql_connect() [function.mysql-connect]: MySQL server has
gone away in C:\\xampp\\htdocs\\posts\\index.php on line 27 Fatal error:
Maximum execution time of 30 seconds exceeded in
C:\\xampp\\htdocs\\posts\\index.php on line 27

I don't really understand what the :2082 is or what it does. In the examples on the php page it uses :3307, but when I log into cpanel on my remote server it always has :2082 after my domain name. In any case 3307 doesn't work either.

Can anyone help me figure out what I'm doing wrong? (or should I be doing something different -- like changing the mysql default host somewhere in the php.ini[??] and then continue to use local host in the mysql_connect ?

Thanks for your help.

That :2082 is the port which mySQL is trying to connect to. It however, will not be the same port as your cPanel. :3307 is the port mySQL traditionally listens on.

I don't use cPanel much, but I believe it tends to set up a subdomain mysql.yourdomain.com that you can connect to.

Past that, make sure that you setup the mySQL user to be able to connect from your local machine.

请联系远程服务器管理,并请求授予您服务器IP地址的权限,以便从您的服务器/网站访问其数据库。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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