提问者:小点点

Mysql身份验证


我有麻烦让我的数据库连接到WAMP。我做这件事已经有5年了,所以我有点生疏了。我将我的Mysql升级到8.0时遇到了这个错误

 Fatal error: Uncaught PDOException: PDO::__construct(): The server requested authentication method unknown to the client [sha256_password] in C:\wamp64\www\dirtyosrs\assets\lib\core\Database.class.php:34 Stack trace: #0 C:\wamp64\www\dirtyosrs\assets\lib\core\Database.class.php(34): PDO->__construct('mysql:host=;dbn...', NULL, NULL, Array) #1 C:\wamp64\www\dirtyosrs\assets\lib\init.php(34): Database->connect() #2 C:\wamp64\www\dirtyosrs\templates\header.php(8): require_once('C:\\wamp64\\www\\d...') #3 C:\wamp64\www\dirtyosrs\index.php(1): include('C:\\wamp64\\www\\d...') #4 {main} Next PDOException: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client in C:\wamp64\www\dirtyosrs\assets\lib\core\Database.class.php on line 34

PDOException: PDO::__construct(): The server requested authentication method unknown to the client [sha256_password] in C:\wamp64\www\dirtyosrs\assets\lib\core\Database.class.php on line 34

我刷新了我的特权,并将插件更改为本机的根。在这一点上我被难倒了。有人能帮帮我吗?

下面是我的数据库类,直到第37行

<?php

/**

>

  • class Database*/class Database{

    专用$IP、$username、$password、$database;

    /**

    • @var PDO*/private$connection;private$Query=0;

    /**

    • 数据库构造函数。
    • @param$ip
    • @param$username
    • @param$password
    • @param$database*/public function__construct($ip,$username,$password,$database){$this->ip=$ip;$this->username=$username;$this->password=$password;$this->database=$database;}

    /**

    • 尝试连接到主机*/public函数connect(){$this->connection=new PDO('mysql:host='.$this->ip.';dbname='.$this->database.';charset=utf8',$this->用户名,$this->密码,数组(PDO::attr_persistent=>true));$this->connection->setattribute(PDO::attr_errmode,PDO::errmode_exception);$this->connection

  • 共1个答案

    匿名用户

    自2018年以来,MySQL8有了一种新的默认类型的安全身份验证方法(sha2),这可能很难在本地主机上使用。为了继续使用传统的身份验证方法,我在我的DockerFile中是这样做的:

    命令:--default-authentication-plugin=mysql_native_password

    如果手动设置,则必须在数据库设置上运行default-authentication命令。

    更多信息请访问:https://mysqlserveteram.com/upgrading-to-mysql-8-0-default-authentication-plugin-considentions/