本地服务器连接到远程mysql

时间:2012-01-22 03:11:18

标签: php mysql

我在这里和互联网上发现了这个问题几次,但没有一个回答帮助了我。

所以我有一个本地apache + php服务器并尝试连接到远程mysql数据库。但脚本返回错误,错误日志中我看到:

PHP Warning:  mysql_connect(): Premature end of data (mysqlnd_wireprotocol.c:553) in D:\\_SERVER\\_WWW\\project\\api\\classes\\database.php on line 13
PHP Warning:  mysql_connect(): OK packet 1 bytes shorter than expected in D:\\_SERVER\\_WWW\\project\\api\\classes\\database.php on line 13
PHP Warning:  mysql_connect(): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file in D:\\_SERVER\\_WWW\\project\\api\\classes\\database.php on line 13

连接脚本(只是连接到服务器的部分):

function db_connect(){
    // Connect to the database server
    $connection = mysql_connect("server.com:3306","username","password",true);
    if (!$connection){
        echo "Could not connect to the Database server, please check your settings";
        die;
    }
...
}

设置PASSWORD的伎俩并不适用于我,有人可以帮助我吗?

谢谢

2 个答案:

答案 0 :(得分:0)

远程需要允许来自服务器IP地址的传入MySQL连接。这可以从远程服务器的MySQL配置文件中添加。

有关如何编辑配置文件的更多信息,请参阅以下详细说明。 http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html

答案 1 :(得分:0)

防火墙需要端口转发到相应系统上的服务器:端口, 这需要为mysql服务器机器预留静态或dhcp地址