|
tid=187560&(1)
) @8 }& p" y! ^- I) Wphp連到mysql出現2行errors : (discuz網頁出現的是連接到mysql錯誤表格,需自行寫一隻連接mysql的php程式來測試)
' z4 Q' A$ `% a# T. J; Y
- T! M. |2 R( W. G( E' v& a2 d" c0 Nmysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers
4 I! \2 o1 e6 X4 @mysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers$ `. W6 R' v. Z6 Q5 n/ W
原因:& g+ X! W; F0 N# s; V
在MySQL 8.0.21中,caching_sha2_password是默認的身份驗證插件,而不是以往的mysql_native_password。所以和php不相容。可以降級php,也可以修改MySQL的配置。 吾人決定修改MySQL的配置:
. t" e& g; y/ ~% X( Tvi /etc/my.cnf 加入下列:
2 V7 K/ [$ R S7 _[mysqld]
* @" i( N; V1 m7 z, C' `
. h+ B( M, d/ }! n( V* Z3 G: t/ }. Jcharacter-set-server=utf83 d. d, J' L) e5 v) ]% M" A) }
default_authentication_plugin=mysql_native_password
' A3 e: M8 R+ u7 A; {6 n1 y
5 G( c6 w6 I, X# d9 T[mysql] z6 K4 I1 ?! r5 \5 b( R( R
default-character-set=utf8* y2 M! M( H: g8 D; A
& D, i" R$ [, T/ t
[client]
: _% L+ ] X* r1 B1 ^$ Edefault-character-set=utf8
% S* W' G! _7 H: k
. f8 i5 t+ i+ ~# z! o7 C然後重啟mysqld1 S+ k# \$ T K# v0 V/ ]* `5 N
service mysqld restart% W% P3 e X! o
搞定!! f! j4 W" } ]! q: j1 ?
3 T2 d+ q/ g0 b& I4 E6 B
註: 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 . J X$ _ \, `& D
! M# _0 u# I7 c! q
7 F; L! ~: O( C: F5 J
當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 即可8 c' y+ M$ L7 L- O
6 B: W& K0 o, M3 I$ o7 h9 r, R4 `* u
; x- u: R# u' W: s* y/ f' k[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., e, v: S. i6 R3 m" q
說明: 千萬不能照它建議用"UTF8MB4",否則無法成功啟動9 b/ J; b( ~9 o4 n/ @. p0 d+ S
+ l6 Y" {) \5 s3 C' }(2)3 }/ y C6 L4 J6 |
(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/ e/ E* C# J& D5 F. D; e
SELECT COUNT(*) FROM common_usergroup WHERE type='special' and system>0
# A+ I. A; _8 A1 e9 G5 U
% A- B4 x: Q. 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 'groups = '' AND starttime<=1532077291 AND (endtime>=1532077291 OR endtime=0) ORD' at line 1
6 t$ }6 L0 F$ m8 G4 sSELECT * 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: F* ~! g' M: x! a# @
2 h3 x5 W4 [9 W8 `. `0 s
因為MySQL 8.0+將system和groups作為了關鍵字,所以不能直接在SQL中將system和groups這兩個詞作為數據庫、數據表、數據表字段中的任意一種使用,如果數據庫名或數據表名或數據表字段名使用了system或groups作為名字,必須使用一對反引號引用起來。寫作`system`或`groups`。
& @$ c/ r8 j. y9 J# b0 _* X- q! R2 o
( r, \5 p; _* H! \第一個錯誤需要找到Discuz!目錄中的source\class\table\table_common_usergroup.php,
' e0 ~! F7 a! K. b$ R5 f$ A將文件中所有的system全部改成`system`,保存後重新上傳到服務器的相同目錄即可。
* K v6 Y/ p) V u
# J# G1 }2 ^, w" t1 V2 y$ W9 |第二個錯誤需要找到Discuz!目錄下中的source\class\table\table_forum_announcement.php,+ m w- p6 C; V& J
將文件中所有的groups全部改為`groups`,保存後重新上傳到服務器的相同目錄即可。8 c7 V4 m* M8 L. P
8 B$ Z5 P0 }; @/ ^! z! M: J- H
如果在MySQL 8+環境下安裝Discuz!,在安裝前需要給install\data\install.sql文件中沒有加引號的所有system逐一添加一對反引號保存重新上傳到服務器的相同目錄,否則也會出現SQL語法錯誤。
1 B# L+ n% U) ^5 Q2 O5 c7 v* m
9 o9 ?( ^; v3 \- |3 ]0 J為了避免語法錯誤,在寫SQL語句時,一定要為所有的數據庫名、數據表名、數據表字段名全部添加一對反引號,像Discuz!這樣的寫法是很不妥的。, c& \3 h$ i! o' A1 J
以上參考: 升級到 MySQL 8.0+ 後Discuz! 更新緩存時出現SQL語法錯誤
4 q1 w& ?$ Z+ [: L8 I2 @ |
|