mysql - 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
/**
类数据库 */ 类数据库 {
私有 $IP、$username、$password、$database;
/**
- @var PDO */ 私有 $connection; 私人 $query = 0;
/**
- 数据库构造函数。
- @param $IP
- @param $用户名
- @param $密码
- @param $database */ public function __construct($IP, $username, $password, $database) { $this->IP = $IP; $this->用户名 = $用户名;$this->密码 = $密码;$this->数据库 = $数据库;}
/**
- 尝试连接主机 */ public function connect() { $this->connection = new PDO('mysql:host='.$this->IP.';dbname='.$this->database.'; charset=utf8', $this->username, $this->password, array(PDO::ATTR_PERSISTENT => true)); $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); }
解决方案
自 2018 年以来,Mysql 8 具有一种新的默认类型的安全身份验证方法 (sha2),很难在 localhost 上工作。为了继续使用传统的 auth 方法,我在我的 Dockerfile 中这样做:
command: --default-authentication-plugin=mysql_native_password
如果您手动设置,则必须在数据库设置中运行 default-authentication 命令。
更多信息在这里:https ://mysqlserverteam.com/upgrading-to-mysql-8-0-default-authentication-plugin-considerations/
推荐阅读
- c++ - 找到与给定数字相乘的数字的有效方法
- chart.js - Chart.js 绘图未与 xAxis 标签对齐
- javascript - 在谷歌应用脚本中结合两个 onEdit() 函数
- javascript - 在 JS 中复制过去时保留样式。(如何从剪贴板获取 stile)
- kubernetes-ingress - 将 nginx-ingress 主机名引用到内部服务
- python - 从 csv 文件创建 mne 数组
- gmail - gcloud 存储上的电子邮件模板图像在 gmail 中不可见
- keras - 损失函数和准确性没有改变 keras
- javascript - JavaScript 如何将欧洲/柏林时区转换为本地时区日期
- android - 使用 Android 应用组件导航预加载导航目的地或异步导航?