MySQL远程连接失败,出现“未知身份验证方法”
作者:互联网
我试图从我的本地机器远程连接MySQL服务器,但我收到以下错误:
Warning: PDO::__construct(): The server requested authentication
method unknown to the client [mysql_old_password] in
C:\xampp\htdocs\ticket\terminal\sync.php
SQLSTATE[HY000] [2054] The server requested authentication method
umknown to the client
我的本地MySQL服务器版本是5.5.27,libmysql – mysqlnd 5.0.10
远程MySQL服务器版本是5.5.23,mysqlnd版本没有公开.
我想这是一个不兼容的密码哈希问题,但我不知道如何解决它.
以下是我的连接代码的一部分
$dsn = 'mysql:host=184.173.209.193;dbname=my_db_name';
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
try {
$online_dbh = new PDO($dsn, 'myusername', 'mypassword', $options);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Congratulations!";
} catch (PDOException $e) {
echo $e->getMessage();
}
解决方法:
假设您使用的是PHP 5.3,您可能会遇到Backward Incompatibility Changes之一:
The new mysqlnd library necessitates the use of MySQL 4.1’s newer 41-byte password format. Continued use of the old 16-byte passwords will cause mysql_connect() and similar functions to emit the error, “mysqlnd cannot connect to MySQL 4.1+ using old authentication.”
如果是,请参阅https://stackoverflow.com/a/1340538/187954以获取有关更新密码的信息.
标签:mysql,pdo,database-connection,remote-access 来源: https://codeday.me/bug/20190918/1811164.html