|
(1)
, ~4 \2 M5 J( E2 |* K* `* Rphp連到mysql出現2行errors : (discuz網頁出現的是連接到mysql錯誤表格,需自行寫一隻連接mysql的php程式來測試)
: [) l! U+ P6 w# W0 x4 G# i* B, f
3 g! u) d9 z( Tmysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers6 {0 X) z! r/ W; f7 J6 j
mysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers
: W4 t6 @# g6 Q原因:
$ R; z+ B4 [+ m K+ S在MySQL 8.0.21中,caching_sha2_password是默認的身份驗證插件,而不是以往的mysql_native_password。所以和php不相容。可以降級php,也可以修改MySQL的配置。 吾人決定修改MySQL的配置:
, f0 J% Y4 d& R6 I1 ?8 ?vi /etc/my.cnf 加入下列:
% B z( x7 A" S i9 Q[mysqld]
4 Q9 O( `' I2 k8 k' p" A
& e: Z# ]7 i. l( R: |% Xcharacter-set-server=utf84 f/ L# D$ j( A" i
default_authentication_plugin=mysql_native_password
( l5 R; d5 m) j) `validate_password.policy=LOW
) _7 J& I P! R; C$ Q. A2 c[mysql]- K% M0 ^8 b0 [8 H7 z( ?7 O
default-character-set=utf8# g9 h; ]5 ?2 A6 x; R
; k7 D# D* P) a
[client], j- r( n$ v/ e+ \
default-character-set=utf8
/ S( b3 y# S g7 [/ ~7 V9 Q- J l. u" n$ M, A: ]+ f4 B/ v$ J( ^
然後重啟mysqld* L/ {3 [" M' Y2 l, h8 T8 G7 u
service mysqld restart4 X& M p- R+ _7 [* v
, Q5 v* K8 R/ C0 u重啟後可能須做下列動作:
: _+ E t9 i4 q2 n0 w9 kmysql -u roor -p - c% ]7 [9 ?+ ]- a2 E& i
SHOW VARIABLES LIKE 'validate_password%';4 \! k7 [5 b4 B3 w
SET GLOBAL validate_password_policy=LOW;ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密碼';搞定!!3 D% n9 M" i* N% S/ c: b" f
/ t* G' X) f9 k [8 a
註: mysqld啟動時,在/var/log/mysql/mysqld.log紀錄著:註: 可以先寫支php程式以測試 ~~~% c- {* {' g/ g0 a: ] |4 }/ m* k9 `
- <?
8 n3 Y) P' l; v - $hostname = "x.x.x.x";
2 n u' C% d9 z$ R( N - $database = "db_name";+ E1 S* g6 h* f, a# S& G1 O/ F/ D
- $username = "user_name";: c" p9 C: K2 A( |/ b
- $password = "pwd";
3 w3 w& S) Y7 K8 @6 b; s9 y. q
, |1 u3 q/ o! w v- $conn = mysqli_connect($hostname, $username, $password,$database) or trigger_error(mysql_error(),E_USER_ERROR);4 i7 q0 y3 b. K L- Q/ c
- mysqli_query($conn ,"SET NAMES utf8");* ^5 r2 p* P2 o+ m7 Y8 A1 U3 L+ J
- 7 T1 l0 s& ]5 }& k! j$ w, Y
- $sql = "select count(*) as total from " . "table_name";- r6 z9 L c% C
- $rec = mysqli_fetch_assoc(mysqli_query( $conn,$sql));% S {& Z" K: ]0 J; c* ^8 C
- echo $rec['total'];
& w/ @: |8 I; @% r! z - mysqli_close($conn);
/ s0 e, n2 D' w3 b% \ - ?>
複製代碼遊客,本帖隱藏的內容需要積分高於 999999999999 才可瀏覽,您當前積分為 0
5 r' ]* H0 `- q9 O2 ]9 Y3 E" W+ x7 O5 e. e, R+ X* v
8 V; y# b! l- m. a, I
當php 7.2.24 connect to mysql server,出現 : - PHP Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /test/connectmysql8.php:9
$ l% w" B* A9 b9 ^" a - Stack trace:6 W9 u' X- G# }/ n- B- O8 L
- #0 {main}* ]; s- ^% p" ]/ d" X; e$ |
- thrown in /test/connectmysql8.php on line 9& g) ~3 k) @2 D/ t1 l0 S
- : U2 z& o3 Z) y
- Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /test/connectmysql8.php:9
G% D. [8 g; ? - Stack trace:
& N) y" s1 m: y4 u. C# U - #0 {main}+ [, l% J% P+ h/ \: G
- thrown in /test/connectmysql8.php on line 9
複製代碼 這是版本相依的問題,只要 yum install php-mysqlnd 或 yum install php-mysqli 即可8 H7 F/ e7 h7 [: T
5 W9 x$ v' i. f5 z0 N- B
" n5 ]1 \ O+ V! i; X[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.
' N( Z. g; `5 I說明: 千萬不能照它建議用"UTF8MB4",否則無法成功啟動/ N( V$ F" h. w1 [6 W9 A/ h$ @- o
6 N! W( U$ O& h* ?9 V
(2)% l1 v& t+ h9 ~4 h6 R/ u" T8 o& S
(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 17 W- C. X9 c* D1 V/ G5 z
SELECT COUNT(*) FROM common_usergroup WHERE type='special' and system>0
9 ]" ?# g4 q9 W/ b' V' i' G$ ]6 t$ z; x$ }; u" e$ J2 H
(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
4 C9 |8 E4 z! s. O PSELECT * 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; C) {. J F6 o& R% [3 @- I
4 D/ a) f+ a4 `# Y" M* p
因為MySQL 8.0+將system和groups作為了關鍵字,所以不能直接在SQL中將system和groups這兩個詞作為數據庫、數據表、數據表字段中的任意一種使用,如果數據庫名或數據表名或數據表字段名使用了system或groups作為名字,必須使用一對反引號引用起來。寫作`system`或`groups`。
8 g* o( b4 l+ D1 d1 V, m* N) D2 y9 O# L9 b
第一個錯誤需要找到Discuz!目錄中的source\class\table\table_common_usergroup.php,
" D; E9 U# z$ \ Z! }7 D將文件中所有的system全部改成`system`,保存後重新上傳到服務器的相同目錄即可。
, ]$ ~& O3 p; S' c8 U8 h2 | \% \( N+ B e6 w: l
第二個錯誤需要找到Discuz!目錄下中的source\class\table\table_forum_announcement.php,
2 X0 \$ x4 q; b0 z! ^7 P2 m將文件中所有的groups全部改為`groups`,保存後重新上傳到服務器的相同目錄即可。$ e; `! Z# L9 _0 L& H$ H; Z7 T7 H
: Z1 u+ }3 c* d
如果在MySQL 8+環境下安裝Discuz!,在安裝前需要給install\data\install.sql文件中沒有加引號的所有system逐一添加一對反引號保存重新上傳到服務器的相同目錄,否則也會出現SQL語法錯誤。$ K9 C* i9 M; [
, J& ~1 K( X2 i& q; B! I為了避免語法錯誤,在寫SQL語句時,一定要為所有的數據庫名、數據表名、數據表字段名全部添加一對反引號,像Discuz!這樣的寫法是很不妥的。
$ Y" |/ K7 H! I) v, |& _以上參考: 升級到 MySQL 8.0+ 後Discuz! 更新緩存時出現SQL語法錯誤( t" N6 @7 m! @7 @7 f
1 \; @3 }/ b, @8 f) A0 k
3 j% \- g4 N, a
) Y# Y M3 k/ m) \( O. u% K1 L U# F, z0 C
|
|
-->
|