PDO connection mysql8.0 pdo::__construct (): Server sent CharSet (255) unknown to the client. Please, report to the developers error

Source: Internet
Author: User
Tags dsn

After installing mysql8.0, try to use PHP to connect to MySQL, always report pdo::__construct (): Server sent CharSet (255) unknown to the client. Please, the developers error, the Internet to find a lot of information, but it is not much use.

Find the official MySQL documentation to know that the original M8.0 has already upgraded the default character set to Ut8mb4, so find the My.cnf file, modified as follows:

 1 [client] 2 port = 3306   3Socket= /Tmp/Mysql.sock4default-character-set = UTF8 56 [MySQL] 7 prompt= "MySQL [\d]>" 8 No-auto-rehash   9default-character-set = UTF8Ten One   [mysqld]  port = 3306   -Socket= /Tmp/Mysql.sock -Default_authentication_plugin=Mysql_native_password the collation-server = Utf8_unicode_ci -   -Basedir= /Usr/Local/MySQL -DataDir= /Data/MySQL +pid-file =/data/mysql/mysql.pid  user = MySQL21 bind-address = 0.0. 0.0  server-id = 1   at   -Init-Connect= 'SET NAMESUTF8'  - character-Set-Server= UTF8

Then use PDO to connect to MySQL

$db=Array(      ' Host ' = ' Your host ',//Set server address' Port ' = ' 3306 ',//Set Port' dbname ' = ' Your DB name ',//Set database name' Username ' = ' Your name ',//set up your account' Password ' = ' your pwd ',//Set Password' CharSet ' = ' utf8 ',//set the encoding format' DSN ' = ' mysql:host=your host;dbname=your db Name;port=3306;charset=utf8 ',   ); //Connection$options=Array(PDO:: Attr_errmode = pdo::errmode_exception,//default is Pdo::errmode_silent, 0, (ignore error mode)Pdo::attr_default_fetch_mode = Pdo::fetch_assoc,//default is Pdo::fetch_both, 4); Try{      $pdo=NewPDO ($db[' DSN '],$db[' username '],$db[' Password '],$options); Var_dump($pdo); }Catch(pdoexception$e){       die(' Database connection failed: '.$e-getMessage ()); }

The results are as follows:

Object (PDO) #1 (0) {}

PDO connection mysql8.0 pdo::__construct (): Server sent CharSet (255) unknown to the client. Please, report to the developers error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.