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