|
(1)
* C: ^1 u2 B7 Y) i+ ~& F! ^+ kphp連到mysql出現2行errors : (discuz網頁出現的是連接到mysql錯誤表格,需自行寫一隻連接mysql的php程式來測試)
5 [( C& c; F7 [" A! r9 i% O6 x# W. x
% y3 i: o; Y9 z0 Q7 t. ]( T& Umysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers
3 v/ l- h+ G5 Z; zmysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers
2 k6 J# F" G2 [* `- I# N原因:
( N- b `0 ~5 i' i* {# K: z在MySQL 8.0.21中,caching_sha2_password是默認的身份驗證插件,而不是以往的mysql_native_password。所以和php不相容。可以降級php,也可以修改MySQL的配置。 吾人決定修改MySQL的配置:" [: X5 r7 p- k% L; ?& s4 u
vi /etc/my.cnf 加入下列:
4 G8 x9 n2 a0 f! }/ x[mysqld]
( T# k; p) @3 x: }% _. o2 H0 x, e9 S( c% Z+ G1 u8 ~
character-set-server=utf88 N0 G% a1 P9 b$ v8 C! X
default_authentication_plugin=mysql_native_password
+ H5 @) ~: P* ?validate_password.policy=LOW f4 t+ G; Z9 ^6 x
[mysql]
~7 x, ^/ l" `- l$ x; Wdefault-character-set=utf81 h P8 `+ f7 E! S! F$ x
1 r1 I* {9 a3 x D' H' d
[client] Y7 E$ H! t) R. _! z
default-character-set=utf86 K8 ] N( P# |" S
9 B6 u/ l6 R: s, u
然後重啟mysqld) d" Z8 Z& }5 O7 ]9 |
service mysqld restart
$ _0 Y9 m, z4 J3 p* O& n
4 U5 R, Y5 b4 J5 e3 B- g重啟後可能須做下列動作:1 N8 I$ ]" p/ o; P( Y9 l& Y
mysql -u roor -p
0 I0 b: z; W9 hSHOW VARIABLES LIKE 'validate_password%';* f% N2 n4 O) U+ A4 k' j- f6 D
SET GLOBAL validate_password_policy=LOW;ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密碼';搞定!!
$ T k/ ~" s7 p8 W( A
2 L. Q | ^; v+ `. L註: mysqld啟動時,在/var/log/mysql/mysqld.log紀錄著:註: 可以先寫支php程式以測試 ~~~
6 I6 \6 }0 o# J4 }( W- <? z& A* o7 N/ R% f
- $hostname = "x.x.x.x";9 z8 f" c/ b9 L, u$ T+ B
- $database = "db_name";3 y3 w0 Z( Q0 Q! z* Q1 @/ k
- $username = "user_name";3 j n! D- k6 Q2 W) ?/ w+ G
- $password = "pwd";
8 x# R& F- u: |% R; } - * V" _" a% W& J! o/ z
- $conn = mysqli_connect($hostname, $username, $password,$database) or trigger_error(mysql_error(),E_USER_ERROR);
6 f' O+ R5 l% a - mysqli_query($conn ,"SET NAMES utf8");1 [. @1 O4 Y& m& P. x
- , w, ]& N' P8 B; R$ r: Z
- $sql = "select count(*) as total from " . "table_name";& p+ f( w8 J% o) I5 M' i/ y
- $rec = mysqli_fetch_assoc(mysqli_query( $conn,$sql));
q" @1 q9 g# l - echo $rec['total'];5 w8 c C) Z0 _% O
- mysqli_close($conn);* g2 V! m# p4 o& I3 p3 A% B2 n
- ?>
複製代碼遊客,本帖隱藏的內容需要積分高於 999999999999 才可瀏覽,您當前積分為 0
j2 k, M1 t# E6 r8 h8 z, x# C8 r1 N
, h( q6 R4 H+ S' j) |( W" T* B3 Y) Z) ?' H3 i* Z5 H2 c: b
當php 7.2.24 connect to mysql server,出現 : - PHP Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /test/connectmysql8.php:92 {" m2 r$ E4 E
- Stack trace:
2 c) q0 X$ B& y6 A, z' Q. F# ^ - #0 {main}
- r. @! Q. I8 d* f+ |8 J7 x) s% x - thrown in /test/connectmysql8.php on line 9
" d P2 t! d( y4 u. z - - O V% L& r9 g
- Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /test/connectmysql8.php:9. K- [) c1 i1 g3 T U: |3 q ^* `
- Stack trace:
: d9 R% x) ^ j! q& o5 Y, B - #0 {main}
8 h( F$ L# k$ S' X - thrown in /test/connectmysql8.php on line 9
複製代碼 這是版本相依的問題,只要 yum install php-mysqlnd 或 yum install php-mysqli 即可" W3 W# `9 [: }1 y' J% Q4 K
. u% n7 F: D( _6 j9 x
/ v. g* y: B z" k: k2 ?! B" Q' w/ |# W/ w7 R
[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.
; O9 F {) Q( t4 k' r( ~說明: 千萬不能照它建議用"UTF8MB4",否則無法成功啟動. `4 U2 N' Z" X9 _1 W1 ~. Z# b
3 I2 F5 r* J6 g, S
(2)
1 n4 t/ V0 p" E( 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 19 b% @' C5 U0 ^# x) W. ]
SELECT COUNT(*) FROM common_usergroup WHERE type='special' and system>0: k' N2 U. j( m8 L, v
# c, S& F. \# _( K
(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
* `" ]+ O1 x& g) D0 A: m, CSELECT * 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$ a7 ~# Q2 |) f* c1 T$ i
1 @+ O2 k0 `8 u# H因為MySQL 8.0+將system和groups作為了關鍵字,所以不能直接在SQL中將system和groups這兩個詞作為數據庫、數據表、數據表字段中的任意一種使用,如果數據庫名或數據表名或數據表字段名使用了system或groups作為名字,必須使用一對反引號引用起來。寫作`system`或`groups`。
; K$ l" E9 w; c# M' Y, }4 N0 d
0 e U3 v8 F0 u g; s3 o' Q& v: E第一個錯誤需要找到Discuz!目錄中的source\class\table\table_common_usergroup.php,: a/ V) b, L# ^, `7 Q: X
將文件中所有的system全部改成`system`,保存後重新上傳到服務器的相同目錄即可。
$ B9 j6 b# s4 u3 C! e- w2 g9 F( l4 g
第二個錯誤需要找到Discuz!目錄下中的source\class\table\table_forum_announcement.php,' }9 c6 D a: d6 G1 E
將文件中所有的groups全部改為`groups`,保存後重新上傳到服務器的相同目錄即可。 |: `2 c a5 y9 y9 k- M N& f
- u& z+ I! Z# z
如果在MySQL 8+環境下安裝Discuz!,在安裝前需要給install\data\install.sql文件中沒有加引號的所有system逐一添加一對反引號保存重新上傳到服務器的相同目錄,否則也會出現SQL語法錯誤。% |( ~$ T/ R7 H* h' _# ]
8 C1 ?1 Y) G) Q3 R* O% |
為了避免語法錯誤,在寫SQL語句時,一定要為所有的數據庫名、數據表名、數據表字段名全部添加一對反引號,像Discuz!這樣的寫法是很不妥的。
0 r. C( M0 i/ X# Y以上參考: 升級到 MySQL 8.0+ 後Discuz! 更新緩存時出現SQL語法錯誤
& ^0 \! X- p& L8 V* F; W( z K2 A4 g% z: r- j! [/ d: R, K
/ N. Z6 G- J* J# c4 R( l7 F
7 L* _3 l* G- n9 v
% j5 @2 B; ?! | |
|
-->
|