coav4u 發表於 2021-3-14 13:06:23

mysqld 升級到8以上遇到的問題

(1)
php連到mysql出現2行errors : (discuz網頁出現的是連接到mysql錯誤表格,需自行寫一隻連接mysql的php程式來測試)

mysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers
mysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers
原因:
在MySQL 8.0.21中,caching_sha2_password是默認的身份驗證插件,而不是以往的mysql_native_password。所以和php不相容。可以降級php,也可以修改MySQL的配置。 吾人決定修改MySQL的配置:
vi /etc/my.cnf加入下列:


character-set-server=utf8
default_authentication_plugin=mysql_native_password


default-character-set=utf8


default-character-set=utf8

然後重啟mysqld
service mysqld restart
搞定!!

註: mysqld啟動時,在/var/log/mysql/mysqld.log紀錄著:註: 可以先寫支php程式以測試 ~~~
<?
$hostname = "x.x.x.x";
$database = "db_name";
$username = "user_name";
$password = "pwd";

$conn = mysqli_connect($hostname, $username, $password,$database) or trigger_error(mysql_error(),E_USER_ERROR);
mysqli_query($conn ,"SET NAMES utf8");

$sql = "select count(*) as total from " ."table_name";
$rec = mysqli_fetch_assoc(mysqli_query( $conn,$sql));
echo $rec['total'];
mysqli_close($conn);
?>於video1主機下 /test/connectmysql8.php


當php 7.2.24connect to mysql server,出現 : PHP Fatal error:Uncaught Error: Call to undefined function mysqli_connect() in /test/connectmysql8.php:9
Stack trace:
#0 {main}
thrown in /test/connectmysql8.php on line 9

Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /test/connectmysql8.php:9
Stack trace:
#0 {main}
thrown in /test/connectmysql8.php on line 9這是版本相依的問題,只要 yum install php-mysqlnd或 yum install php-mysqli 即可


--character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
說明: 千萬不能照它建議用"UTF8MB4",否則無法成功啟動

(2)
(1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'system>0' at line 1
SELECT COUNT(*) FROM common_usergroup WHERE type='special' and system>0

(1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups = '' AND starttime<=1532077291 AND (endtime>=1532077291 OR endtime=0) ORD' at line 1
SELECT * FROM forum_announcement WHERE type!=2 AND groups = '' AND starttime<=1532077291 AND (endtime>=1532077291 OR endtime=0) ORDER BY displayorder, starttime DESC, id DESC LIMIT 1

因為MySQL 8.0+將system和groups作為了關鍵字,所以不能直接在SQL中將system和groups這兩個詞作為數據庫、數據表、數據表字段中的任意一種使用,如果數據庫名或數據表名或數據表字段名使用了system或groups作為名字,必須使用一對反引號引用起來。寫作`system`或`groups`。

第一個錯誤需要找到Discuz!目錄中的source\class\table\table_common_usergroup.php,
將文件中所有的system全部改成`system`,保存後重新上傳到服務器的相同目錄即可。

第二個錯誤需要找到Discuz!目錄下中的source\class\table\table_forum_announcement.php,
將文件中所有的groups全部改為`groups`,保存後重新上傳到服務器的相同目錄即可。

如果在MySQL 8+環境下安裝Discuz!,在安裝前需要給install\data\install.sql文件中沒有加引號的所有system逐一添加一對反引號保存重新上傳到服務器的相同目錄,否則也會出現SQL語法錯誤。

為了避免語法錯誤,在寫SQL語句時,一定要為所有的數據庫名、數據表名、數據表字段名全部添加一對反引號,像Discuz!這樣的寫法是很不妥的。
以上參考:   升級到 MySQL 8.0+ 後Discuz! 更新緩存時出現SQL語法錯誤
頁: [1]
查看完整版本: mysqld 升級到8以上遇到的問題