|
tid=187560&(1)8 ~% @" z& u9 {
php連到mysql出現2行errors : (discuz網頁出現的是連接到mysql錯誤表格,需自行寫一隻連接mysql的php程式來測試)
3 M+ Y3 @* G0 ~1 a- o2 N% |
% }0 I1 \& [" w' n* smysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers
! |+ Z' z& u3 [: f( Nmysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers
4 R0 v4 w+ f& t9 u: ~原因:- _2 C9 L( v! v! n; h% ^2 y
在MySQL 8.0.21中,caching_sha2_password是默認的身份驗證插件,而不是以往的mysql_native_password。所以和php不相容。可以降級php,也可以修改MySQL的配置。 吾人決定修改MySQL的配置:3 J$ w7 ?9 l* Y: x- f) @
vi /etc/my.cnf 加入下列:6 e2 d8 J7 j$ y& ] c1 ]' s5 G
[mysqld], |/ K4 b' h7 h+ X9 }8 }) J A1 e9 ?
5 u3 n$ E. P' Y7 _5 l" ^1 a6 V: Hcharacter-set-server=utf8
4 |" q" L# u/ |# e# R( v) Wdefault_authentication_plugin=mysql_native_password
% D1 P0 X- L0 l4 @+ A4 f6 m l
' d5 q o, ]7 n' D4 H5 b6 L8 Y) O[mysql]" K. h' a8 r" P; \. s, l
default-character-set=utf8
7 Z+ ?1 i" w C9 h2 k* ]9 ~" Z y( E# Q7 G! _2 v% K& A
[client]6 g( Y' T7 p, k0 q: L
default-character-set=utf8
4 w8 \4 q) l8 ~; O; t2 Z( X$ d. X- J' { M
然後重啟mysqld3 ^% c) Z( k. b/ R8 p4 {! T
service mysqld restart+ l f4 c. h, X6 _+ ]$ Q: L
搞定!!0 ~& Y7 E6 R" R2 D
, c% ?* ~0 ~6 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 + s* J( t# k6 W; T+ P& d6 k s" }* I
0 ?* C6 l# Q- a# k5 v$ K
, H' P! N( }5 h% y- t3 C當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 即可
$ o0 T0 P( {! r& Z9 x2 p
8 Q/ Z9 a2 ]( B, G) \5 y8 {6 U: [/ K% I- w C3 F" n X( M
[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.3 u% z c( l0 z, R. I/ ]
說明: 千萬不能照它建議用"UTF8MB4",否則無法成功啟動
$ b6 A! M1 U4 O" z
5 z0 V) S- W9 b+ _- `% j& F(2); y# ~" S7 m* [( w: }. j: ^& 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
* K) B5 C% r4 jSELECT COUNT(*) FROM common_usergroup WHERE type='special' and system>0
. B% P. Y3 p: I) W9 Z! t. T( r/ E( |& s: J) k$ Y& A+ g4 e, L
(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' t5 z4 @+ O, _# P) G
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+ I/ Q ^% O( t! E3 y0 O: o
8 C! v1 X9 b' b, Z; m, @! n) B因為MySQL 8.0+將system和groups作為了關鍵字,所以不能直接在SQL中將system和groups這兩個詞作為數據庫、數據表、數據表字段中的任意一種使用,如果數據庫名或數據表名或數據表字段名使用了system或groups作為名字,必須使用一對反引號引用起來。寫作`system`或`groups`。' G& M# M2 u d2 _+ O: d! d; H
% t9 M; j9 F6 D/ B第一個錯誤需要找到Discuz!目錄中的source\class\table\table_common_usergroup.php,
/ d( t X. S+ Q2 @3 ~" Z) A將文件中所有的system全部改成`system`,保存後重新上傳到服務器的相同目錄即可。
! v) Z5 k6 p' }" e; ?" R
1 d; U7 O- u4 H, {2 @% V第二個錯誤需要找到Discuz!目錄下中的source\class\table\table_forum_announcement.php,
: S. t$ \0 J3 K3 A7 X將文件中所有的groups全部改為`groups`,保存後重新上傳到服務器的相同目錄即可。
1 |- e4 z" ~! ]/ V( M$ x. s0 B7 A: q
如果在MySQL 8+環境下安裝Discuz!,在安裝前需要給install\data\install.sql文件中沒有加引號的所有system逐一添加一對反引號保存重新上傳到服務器的相同目錄,否則也會出現SQL語法錯誤。0 X# L3 s3 ~* _ i! f: D* W+ W
- ] U0 a5 o0 k. C' q
為了避免語法錯誤,在寫SQL語句時,一定要為所有的數據庫名、數據表名、數據表字段名全部添加一對反引號,像Discuz!這樣的寫法是很不妥的。- d: b, }# L8 ?; M) W' j! z
以上參考: 升級到 MySQL 8.0+ 後Discuz! 更新緩存時出現SQL語法錯誤; e, }8 V2 c, {: k
|
|