|
tid=187560&(1)
6 [# l- T. t0 w mphp連到mysql出現2行errors : (discuz網頁出現的是連接到mysql錯誤表格,需自行寫一隻連接mysql的php程式來測試)
1 S+ D6 [5 M$ ^& E# {0 e
" r2 U: \- a' b% H, J7 P7 nmysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers
7 G% p2 A6 h5 \- D' v' jmysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers
( T6 Z* e- o+ @& V6 ]7 }原因:5 J1 t& [ k# F8 B, {
在MySQL 8.0.21中,caching_sha2_password是默認的身份驗證插件,而不是以往的mysql_native_password。所以和php不相容。可以降級php,也可以修改MySQL的配置。 吾人決定修改MySQL的配置:: G/ Q2 n$ b$ Q" ~5 z" P6 y" j
vi /etc/my.cnf 加入下列:
1 o1 ?4 _% Y! q: c% m+ v( @ P! ^[mysqld]
& y) k% }/ }. X; _" A& W" O) ~% i' m( ~9 m2 m- K- @
character-set-server=utf8. C7 Y9 S- v+ W, ~$ Z. a2 l
default_authentication_plugin=mysql_native_password
4 ~) e) e o( G' H. R
! e/ r# M' [# _, Q9 Y[mysql]# O5 c5 x2 B( V( ]
default-character-set=utf8
: p; z- b# U1 z& R2 z; ^8 l O3 p- U) w* t3 b0 |: G4 @
[client]0 Q4 g" h L; C3 s# N4 W
default-character-set=utf8, q& z& Q1 _- |/ ]' B; k% K
& D. c( W4 Y- A" a) z+ }9 f8 @' D然後重啟mysqld0 D) g) |* j5 |; G) @7 c
service mysqld restart- d- ?+ t1 Z9 M
搞定!!! d P! s1 i# Z8 e4 a
0 y5 ^8 l1 N4 q7 Z& A' e) N- k( W% U) H註: 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 , }8 i4 f* x5 X3 H! a" A" v7 k
+ u: C: o: X( d, E/ |) l) B) `, z- K: }- I) q8 U! J/ K& \. b
當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 即可 |, G0 y: r4 ]6 @% Z3 X- a
" z: D7 p+ [) j" t# ?$ i6 p
' [/ @% r8 a# Y$ ^[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.: a/ {9 q w# S' Z) i
說明: 千萬不能照它建議用"UTF8MB4",否則無法成功啟動
+ p* R# B/ ^+ |# v1 U5 B7 m6 u/ N X( Q6 M+ {. g0 C) A' b
(2)
7 D0 ~: C' H& ^# Q- u3 M4 a(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/ ]# X9 _2 i' U5 y1 ^. d
SELECT COUNT(*) FROM common_usergroup WHERE type='special' and system>0
- n6 m* t" I/ ^: ^4 a
* N- N1 a8 G: W3 |; Y: R+ T(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
7 j0 A1 J& l: t: U9 `/ R" KSELECT * 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. Y& H6 q! v7 r! d- Z% z
$ h& Y; I0 w$ b6 Q2 @2 A
因為MySQL 8.0+將system和groups作為了關鍵字,所以不能直接在SQL中將system和groups這兩個詞作為數據庫、數據表、數據表字段中的任意一種使用,如果數據庫名或數據表名或數據表字段名使用了system或groups作為名字,必須使用一對反引號引用起來。寫作`system`或`groups`。
( w5 l+ k* u, ~! ^2 H- g, z* @9 U3 N1 X
第一個錯誤需要找到Discuz!目錄中的source\class\table\table_common_usergroup.php,( z3 A0 J# b2 c; {
將文件中所有的system全部改成`system`,保存後重新上傳到服務器的相同目錄即可。
S4 b" k; P& H7 z
1 p: @4 H8 \/ n( {第二個錯誤需要找到Discuz!目錄下中的source\class\table\table_forum_announcement.php,
0 b0 E8 N8 p( k; x: M. e1 r將文件中所有的groups全部改為`groups`,保存後重新上傳到服務器的相同目錄即可。' o1 d% s, Y4 o' k
, T: A3 g; {- _5 @2 ]* i% E5 f( S H
如果在MySQL 8+環境下安裝Discuz!,在安裝前需要給install\data\install.sql文件中沒有加引號的所有system逐一添加一對反引號保存重新上傳到服務器的相同目錄,否則也會出現SQL語法錯誤。2 Z$ I- d2 D0 }: a
2 k1 R Q/ c1 ~0 I8 R為了避免語法錯誤,在寫SQL語句時,一定要為所有的數據庫名、數據表名、數據表字段名全部添加一對反引號,像Discuz!這樣的寫法是很不妥的。% H- P1 a( B( ^+ \0 \. z( R
以上參考: 升級到 MySQL 8.0+ 後Discuz! 更新緩存時出現SQL語法錯誤( E, [& V* J$ T0 m
|
|