|
|
tid=187560&(1)7 ?! Z1 b+ T+ `$ y0 Z$ W0 i6 f1 a
php連到mysql出現2行errors : (discuz網頁出現的是連接到mysql錯誤表格,需自行寫一隻連接mysql的php程式來測試)- a% f6 u$ s; w5 x# O' \& V) V
: p0 ^' z0 f! l! F" ?4 s
mysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers! u$ r: ^% K9 K( K+ k$ [6 M5 t7 S. Y
mysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers/ H- o% M2 ?+ i# v
原因:
2 x# ]% V( Q1 Z$ g在MySQL 8.0.21中,caching_sha2_password是默認的身份驗證插件,而不是以往的mysql_native_password。所以和php不相容。可以降級php,也可以修改MySQL的配置。 吾人決定修改MySQL的配置:
& B9 ^5 t( \$ y! pvi /etc/my.cnf 加入下列:
) B) N$ L u' J$ t# s; }[mysqld]
# c- j$ Z; m( ^# V: K+ E! L, \
, U3 _; g0 q$ ?" H5 U. h# C1 G" Icharacter-set-server=utf89 B5 y8 Z! Z$ V$ f; o) h0 O8 s
default_authentication_plugin=mysql_native_password8 y P2 M% t8 \9 g
% ?, n8 j4 p( K3 S7 \
[mysql]
9 g* X7 w( V- S" R0 Z. Y: Ldefault-character-set=utf8: ?# H4 `. g3 P7 e3 {
$ D5 J* l& e# I. z# G[client]1 M- O# v4 v- F' |, I$ F
default-character-set=utf8; c/ H3 R8 w$ P. ~( W8 a
5 i' b$ s* T2 ~5 {% D! i2 ~然後重啟mysqld
g4 w- B% w1 v4 J6 |service mysqld restart! O6 [9 X' Q3 U8 X
搞定!!! B9 A [9 x: k+ y
( l1 J6 e5 K; `# P8 z
註: 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 7 }9 z% X+ [, E. z4 O4 i
1 x5 ~& T# b2 K! ?
+ k5 |3 F" t% }/ b8 s1 u# }當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 即可: \0 f1 L5 F- Y4 |( L! x% `) t( Z+ b
! h+ T. q' O6 o5 Q6 u
6 k8 M' o- N# X' E8 ^% ?1 t[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.) v" Y r4 s7 q5 k9 y Y$ f
說明: 千萬不能照它建議用"UTF8MB4",否則無法成功啟動. A n* w$ m- `9 S' J# |( a# e
. v: M- ]" H* V! c% F7 A(2)* e" O! I; d) y) m: L5 j2 f
(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
0 K6 ~; v3 Q/ nSELECT COUNT(*) FROM common_usergroup WHERE type='special' and system>0
# a$ P0 c% N) Y1 [: \8 |) j' _
/ |' w n9 N% E: U(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 11 w" c/ X# q% P7 _
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 10 b p' x3 k8 E! G5 b7 y5 @
/ ~0 l0 Z& o" |; r( F因為MySQL 8.0+將system和groups作為了關鍵字,所以不能直接在SQL中將system和groups這兩個詞作為數據庫、數據表、數據表字段中的任意一種使用,如果數據庫名或數據表名或數據表字段名使用了system或groups作為名字,必須使用一對反引號引用起來。寫作`system`或`groups`。
+ l6 P$ k- q% F0 }6 Q2 m
4 o: {8 [- ~& b% F1 Y第一個錯誤需要找到Discuz!目錄中的source\class\table\table_common_usergroup.php,
- O9 P* c) e% C( A! C1 A將文件中所有的system全部改成`system`,保存後重新上傳到服務器的相同目錄即可。
8 a G9 }7 Q$ l
7 U6 K0 W4 ^0 F9 R# K7 W/ r% j第二個錯誤需要找到Discuz!目錄下中的source\class\table\table_forum_announcement.php,, _0 J% a' D9 B) l
將文件中所有的groups全部改為`groups`,保存後重新上傳到服務器的相同目錄即可。
" A7 Q3 D3 `7 L4 u N% ?( w. M; p) v# T
如果在MySQL 8+環境下安裝Discuz!,在安裝前需要給install\data\install.sql文件中沒有加引號的所有system逐一添加一對反引號保存重新上傳到服務器的相同目錄,否則也會出現SQL語法錯誤。
i) m: A3 H3 ]9 f, O/ [! |
+ Z9 ^8 p! g8 E$ ?為了避免語法錯誤,在寫SQL語句時,一定要為所有的數據庫名、數據表名、數據表字段名全部添加一對反引號,像Discuz!這樣的寫法是很不妥的。2 `. P$ E' ]0 D) S& |: C1 p) W
以上參考: 升級到 MySQL 8.0+ 後Discuz! 更新緩存時出現SQL語法錯誤
1 H* I* k+ x7 E e |
|