mysql 8 错误 Server sent charset unknown to the client

Mysql 2020-07-22 阅读 60 评论 0

问题描述

安装 mysql 8 之后,尝试使用 PHP 连接 mysql 并读取数据。

$dsn = "mysql:dbname=test;host=localhost;charset=utf8";
$user = "root";
$password = "root";
try {
    $pdo = new PDO($dsn, $user, $password);
    $res = $dbh->query($sql);
} catch (PDOException $e) {
    echo $e->getMessage();
}

但是报错了。

Server sent charset unknown to the client. Please, report to the developers

解决方法

MySQL 8将默认字符集更改为utf8mb4。但是有些客户不知道这个字符集。因此,当服务器向客户端报告其默认字符集时,客户端不知道服务器的含义时,它将引发此错误。

编辑 my.cnf,指定编码,增加以下内容。

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
最后更新 2020-07-22
MIP.watch('startSearch', function (newVal, oldVal) { if(newVal) { var keyword = MIP.getData('keyword'); console.log(keyword); // 替换当前历史记录,新增 MIP.viewer.open('/s/' + keyword, {replace: true}); setTimeout(function () { MIP.setData({startSearch: false}) }, 1000); } }); MIP.watch('goHome', function (newVal, oldVal) { MIP.viewer.open('/', {replace: false}); });