由于MySQL 8.0默认字符集是 utf8mb4,PHP访问会报错,报错信息如下所示:
PHP Warning: mysqli_connect(): Server sent charset (255) unknown to the client. Please, report to the dev
elopers in /root/php_utf8mb4/conn.php on line 4PHP Wa服务器托管网rning: mysqli_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to
the developers in /root/php_utf8mb4/conn.php on line 4数据库链接错误
Se服务器托管网rver sent charset unknown to the client. Please, report to the developers
解决方案
在/etc/my.cnf配置文件添加如下
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
见红色的参数,并重启mysqld进程生效。
之后,再通过php连接一切正常。
测试代码:
getMessage();
}
?>
感谢研发工程师@豆豆老爹的技术支持。
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net