本地服务器连接远程MySQL

3
我发现这个问题在互联网上出现了很多次,但没有一个答案能够帮助到我。
因此,我有一台本地的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;
    }
...
}

我尝试设置密码的技巧没有奏效,能否有人帮助我?

谢谢。


如果不允许远程连接,则无法直接连接到服务器。 - Nazariy
对吧?我认为远程连接设置应该没问题,但不知道这里出了什么问题。 - Tomas
不要输出固定的字符串,而是输出错误原因:"if (!$connection) { die(mysql_error()); }"。它会告诉你出了什么问题,只要你让它说话。 - Marc B
正如我所预料的那样,在日志中出现了与之相同的错误:“mysqlnd无法使用旧的不安全身份验证连接到MySQL 4.1+。请使用管理工具使用命令SET PASSWORD = PASSWORD('your_existing_password')重置密码。这将在mysql.user中存储一个新的、更安全的哈希值。如果此用户在PHP 5.2或更早版本中执行的其他脚本中使用,您可能需要从my.cnf文件中删除old-passwords标志。” - Tomas
2个回答

0
防火墙需要将端口转发到相应系统上的服务器:端口,这需要为mysql服务器机器进行静态或动态主机配置地址保留。

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接