php5 與 mysql8的兼容問題
環境
Linux: ubuntu20.04
Mysql: 8.0.33
Php: 5.6
代碼
# cat test.php
<?php$link = mysqli_connect("127.0.0.1", "root", "123456");if ($link) {echo "ok";
} else {echo "fail";
}
?>
復現方法
php test.php
問題描述
報錯如下:
PHP Warning: mysqli_connect(): Server sent charset (255) unknown to the client. Please, report to the developers in /root/test.php on line 2
PHP Warning: mysqli_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers in /root/test.php on line 2
原因
php5-php7與mysql8不兼容,mysqli無法使用。
MySQL8.0默認是utfmb4的格式,PHP默認的是UTF8格式
解決辦法
將php升級到8.0以上,或者將mysql降到8以下