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 ...
随机推荐
- python3.x Day4 内置方法,装饰器,生成器,迭代器
内置方法,就是python3提供的各种函数,可以认为是关键字,帮助进行一些列的牛x运算. abs()#取绝对值 all([])#可迭代对象中的所有元素都为True 则为True,只要至少一个为Fals ...
- Python之游戏开发-飞机大战
Python之游戏开发-飞机大战 想要代码文件,可以加我微信:nickchen121 #!/usr/bin/env python # coding: utf-8 import pygame impor ...
- 模拟Django的admin自定义stark组件
1.新建Django项目--新建app:app01和stark--在settings中配置app和数据库--在models.py中新建模型表--完成数据库迁移 2.在stark下的apps.py中: ...
- Master of Subgraph
Problem E. Master of SubgraphYou are given a tree with n nodes. The weight of the i-th node is wi. G ...
- 【http_load】http_load性能测试工具使用详解
1.什么是http_loadhttp_load是一款基于Linux平台的web服务器性能测试工具,用于测试web服务器的吞吐量与负载,web页面的性能. 2.http_load的安装1)下载地址wge ...
- msp430入门学习10
msp430的定时器--看门狗 msp430入门学习
- hdu - 2066 一个人的旅行(基础最短路)
http://acm.hdu.edu.cn/showproblem.php?pid=2066 把与草儿相连的城市最短距离置为0,然后进行dijkstra,在t个城市里找出距离最近的一个即可. #inc ...
- POJ 3469_Dual Core CPU
题意: N个模块可以在A,B两个核上运行,分别需要A[i]和B[i],模块之间需要传递数据,若两个模块在同一核上,则不需要花费,否则需要花费w[i].问最少需要花费多少? 分析: 用最小的费用将两个对 ...
- Ubuntu 16.04在搭建Redis Cluster搭建时,使用gem install redis时出现:ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /var/lib/gems/2.3.0 directory.
注意:千万不要使用sudo来执行gem install redis. 解决方法: sudo apt-get update sudo apt-get install git-core curl zlib ...
- Visual studio 2008 的语法高亮插件 WordLight
前段时间一直在使用matlab,今天需要使用vs2008,而用惯了matlab,习惯了其中一项选中变量高亮的设置,突然回来使用VS,感到各种不适应,顿时想到了一个词:矫情 呵呵,于是在网上找各种插件, ...