PDO连接mysql8.0报PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers错误
安装mysql8.0之后,尝试使用php连接mysql,总是报PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers错误,网上找了很多资料,然而都没有多大用处。
查找了mysql官方说明文档才知道原来M8.0已经已经把默认字符集升级成ut8mb4了,于是找到my.cnf文件,修改如下:
1 [client]
2 port = 3306
3 socket = /tmp/mysql.sock
4 default-character-set = utf8
5
6 [mysql]
7 prompt="MySQL [\d]> "
8 no-auto-rehash
9 default-character-set = utf8
10
11 [mysqld]
12 port = 3306
13 socket = /tmp/mysql.sock
14 default_authentication_plugin = mysql_native_password
15 collation-server = utf8_unicode_ci
16
17 basedir = /usr/local/mysql
18 datadir = /data/mysql
19 pid-file = /data/mysql/mysql.pid
20 user = mysql
2 bind-address = 0.0.0.0
22 server-id = 1
23
24 init-connect = 'SET NAMES utf8'
25 character-set-server = utf8
然后使用PDO连接mysql
$db = array(
'host' => 'your host', //设置服务器地址
'port' => '3306', //设端口
'dbname' => 'your db name', //设置数据库名
'username' => 'your name', //设置账号
'password' => 'your pwd', //设置密码
'charset' => 'utf8', //设置编码格式
'dsn' => 'mysql:host=your host;dbname=your db name;port=3306;charset=utf8',
); //连接
$options = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, //默认是PDO::ERRMODE_SILENT, 0, (忽略错误模式)
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, // 默认是PDO::FETCH_BOTH, 4
); try{
$pdo = new PDO($db['dsn'], $db['username'], $db['password'], $options);
var_dump($pdo);
}catch(PDOException $e){
die('数据库连接失败:' . $e->getMessage());
}
结果如下:
object(PDO)#1 (0) { }
PDO连接mysql8.0报PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers错误的更多相关文章
- PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers
微擎出错信息: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2054] Server s ...
- Mac环境下PHP连接mysql提示Server sent charset (255) unknown和(HY000/2054)
错误提示: mysqli_connect(): Server sent charset (255) unknown to the client. Please, report to the devel ...
- php7.3连接MySQL8.0报错 PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]
报的错误: In Connection.php line : SQLSTATE[HY000] [] The server requested authentication method unknown ...
- SQLyog连接MySQL8.0报2058错误的解决方案
引言 用SQLyog连接MySQL8.0(社区版:mysql-installer-community-8.0.15.0.msi),出现错误2058(Plugin caching_sha2_passwo ...
- android studio连接MYSQL8.0报错:java.long.unsupportedOperation处理方案
纠结了我大概一个星期了! 下载的别人的demo测试,因为还没学线程连接网络啥的 对方使用的版本是MYSQL5.1.14,我使用的8.0.18,同样都是阿里云服务器自建数据库. 由于是版本8.0,所以在 ...
- Navicat for MySQL 连接Mysql8.0 报 1251
先设置Mysql全局 cmd下输入: mysql -uroot -p root密码 use mysql; update user set host = "%" where user ...
- kettle 连接 mysql8.0 报错的解决办法 org.pentaho.di.core.exception.KettleDatabaseException: Error occurred while trying to connect to the database Error connecting to database: (using class org.gjt.mm.mysql.
1.下载 mysql8.0 驱动放到 如下目录中 mysql8.0以上的驱动下载链接:mysql-connet-8.0.13 2.配置你连接的数据库 找到如下文件打开编辑 连接信息:下面是我本地的配置 ...
- IntelliJ IDEA集成工具Database连接MySQL8.0报错的解决方法
直接用默认配置连接的话,会报以下错误: Connection to MySQL - @localhost failed. [08001] Could not create connection to ...
- sqlalchemy 连接mysql8.0报 RuntimeError: cryptograpy si requeired for sha256_password 错误
cryptography is required for sha256_password or caching_sha2_password 需要cryptography模块的支持才能连接需要sha25 ...
随机推荐
- Buffer.compare()
Buffer.compare(buf1, buf2) buf1 {Buffer} buf2 {Buffer} 返回:{Number} 比较 buf1 和 buf2 通常用于 Buffer 数组的排序目 ...
- c++基础_字符串对比
#include <iostream> #include <string.h> #include <algorithm> using namespace std; ...
- 第七章习题G题
题意 给出如图案例,要你从某一点开始走,一直走到极限(即无法再进行扩展),这时你走过的点会连成一个数,不同的走法当然会有不同的数,要求是输出最大的数(注意每个方块走过一次就不能再走) 思路 •1.枚举 ...
- python——进制间的转换
int(string_num, n) string_num表示某种进制的字符串,n表示string_num是什么进制数 2.8.16 进制转为10进制:使用int()或者eval() 10 进制转为 ...
- Java面向对象学习-----类的成员变量
类的成员变量: 猜数字游戏:一个类A有一个成员变量v,通过随机产生一个100内的整数给v赋值.定义一个方法,对A类的成员变量v进行猜. 没有猜对的情况下提示如果大了则提示大了,小了则提示小了,并且 ...
- CodeForcesGym 100512D Dynamic LCA
Dynamic LCA Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForcesGym. ...
- xtu read problem training 4 B - Multiplication Puzzle
Multiplication Puzzle Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. O ...
- Leetcode 187.重复的DNA序列
重复的DNA序列 所有 DNA 由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:"ACGAATTCCG".在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮 ...
- 2018/2/14 x-pack的学习
x-pack是什么?它能提供的作用如下,下面描述的这些功能都属于x-park:Shield: 提供对数据的 Password-Protect,以及加密通信.基于角色的权限控制,IP 过滤,审计,可以有 ...
- UUID使用
import java.util.UUID; public static String getUUID() { UUID uuid =UUID.randomUUID(); String str = u ...