|
|
tid=187560&(1)
2 ^5 s8 k# A5 q* d, ^0 L: N, uphp連到mysql出現2行errors : (discuz網頁出現的是連接到mysql錯誤表格,需自行寫一隻連接mysql的php程式來測試)2 ]' e5 x. l9 e; i
6 l+ }3 V# Y$ U; m0 Y/ x$ `mysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers$ t, k, K- l R, B
mysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers
. U3 O+ ^, p; E, A/ O6 \1 z' o; u9 ?原因:+ e8 V- g! c; y; K; Q
在MySQL 8.0.21中,caching_sha2_password是默認的身份驗證插件,而不是以往的mysql_native_password。所以和php不相容。可以降級php,也可以修改MySQL的配置。 吾人決定修改MySQL的配置:
- w0 y- u6 N. Y8 pvi /etc/my.cnf 加入下列:/ p* [& t; g: W; z$ t
[mysqld]- n0 ]( C, A7 ?) F9 c, I
& ^% G f4 {7 ^, Acharacter-set-server=utf8
' R2 x& M4 u! ^* E8 Ddefault_authentication_plugin=mysql_native_password
" Q% r4 W$ ~, U% q# {# h
6 [. n. a- R' E2 g[mysql]1 U( Z9 i P+ g/ k
default-character-set=utf8( x' C9 v6 T& Q' T
+ u: p1 ]; M5 A6 U9 o) `
[client]
4 z$ {( n2 h8 }( b6 |default-character-set=utf8* ~7 j$ E9 b6 F
) C) D- {5 l/ `
然後重啟mysqld
# K' Q/ L7 v, H7 l: {0 t# }0 }service mysqld restart. | J. a/ e' T ^; C
搞定!!
) @! W* {. M0 G# Q; L9 d% G7 i6 r% _. S: J' g
註: 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);
- ?>
複製代碼遊客,本帖隱藏的內容需要積分高於 999999999999 才可瀏覽,您當前積分為 0 + t5 [0 l4 y5 Q$ f0 R
. e. i! E9 _; g0 N6 `$ g* L, x* }8 |3 w9 Z
當php 7.2.24 connect 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 即可8 c- N+ V4 } x! @* x" H1 k$ m
* ?+ S! j, ?6 e
+ A5 s8 l3 k6 ^8 J# @[Warning] [MY-013242] [Server] --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.
1 F3 i7 O; z3 y$ E [說明: 千萬不能照它建議用"UTF8MB4",否則無法成功啟動
4 w9 m3 m2 _$ E5 B2 w) f
' {# ?. @/ u8 i: t" p(2)9 b0 B$ i; g2 \' b
(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: v/ @* I `( o" B4 }0 P
SELECT COUNT(*) FROM common_usergroup WHERE type='special' and system>0+ [( @& r$ [! s1 z) v0 ^
7 d2 b" b! A$ N) s7 \
(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
( I& g |3 B- U3 d+ J- ^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
9 H# `4 [1 K7 v2 K/ k# n( C3 a& w
' J, t5 V1 c* Z因為MySQL 8.0+將system和groups作為了關鍵字,所以不能直接在SQL中將system和groups這兩個詞作為數據庫、數據表、數據表字段中的任意一種使用,如果數據庫名或數據表名或數據表字段名使用了system或groups作為名字,必須使用一對反引號引用起來。寫作`system`或`groups`。, @+ u i$ c0 a) F
1 f$ ~3 s# | S$ u: Q
第一個錯誤需要找到Discuz!目錄中的source\class\table\table_common_usergroup.php,8 m; E# o) Z; X: ?
將文件中所有的system全部改成`system`,保存後重新上傳到服務器的相同目錄即可。
8 z0 S( l* e3 K3 F6 v/ @7 D, v2 }
" c/ p' J0 }2 k1 v- A, C第二個錯誤需要找到Discuz!目錄下中的source\class\table\table_forum_announcement.php,
9 a6 y( a7 u1 _$ m$ o6 w; w0 X將文件中所有的groups全部改為`groups`,保存後重新上傳到服務器的相同目錄即可。. c. c% ^- h6 c, }$ J
" \1 D; Z' N8 e3 e' n4 l
如果在MySQL 8+環境下安裝Discuz!,在安裝前需要給install\data\install.sql文件中沒有加引號的所有system逐一添加一對反引號保存重新上傳到服務器的相同目錄,否則也會出現SQL語法錯誤。- z0 h1 p. ^4 ~8 B
, d5 `' _' L/ r& y0 D為了避免語法錯誤,在寫SQL語句時,一定要為所有的數據庫名、數據表名、數據表字段名全部添加一對反引號,像Discuz!這樣的寫法是很不妥的。3 S1 s5 e6 P4 H% K5 |- v: u4 V
以上參考: 升級到 MySQL 8.0+ 後Discuz! 更新緩存時出現SQL語法錯誤: [( _# \. G6 C, a+ I
|
|