|
|
tid=187560&(1)
; g) N' r$ d+ `' s0 i3 B2 i( lphp連到mysql出現2行errors : (discuz網頁出現的是連接到mysql錯誤表格,需自行寫一隻連接mysql的php程式來測試)/ N4 K( o4 u! Q5 |
! f3 R: T" C- D, f" \
mysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers; E, g* q" R# [4 Y% U# a
mysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers5 v* h+ {4 \; E: q; Y8 D
原因:& o" d$ g# A( a O3 S
在MySQL 8.0.21中,caching_sha2_password是默認的身份驗證插件,而不是以往的mysql_native_password。所以和php不相容。可以降級php,也可以修改MySQL的配置。 吾人決定修改MySQL的配置:
( E/ A: y# S) V; Vvi /etc/my.cnf 加入下列:
& q+ L/ o1 p. n' T7 \7 l8 x[mysqld]
; C F* j5 e& g3 Q1 C6 q) {
4 ]% ^6 U; ?: H* M+ [- {character-set-server=utf8
* V) x4 z5 y* q- w) xdefault_authentication_plugin=mysql_native_password( y( T* e8 s7 K
4 a- N' ?' e; l6 W1 ]7 V
[mysql]/ |4 k* N b& m) Y- P A
default-character-set=utf8
( m* M9 d$ G2 Z+ `' S/ R. X
. ?% D) {* [( a# T[client]
" D' \9 z" Y) xdefault-character-set=utf8
$ Q* e4 c) ?7 t: s
2 B5 [8 s% p0 ]0 h, o, a; ]然後重啟mysqld6 [/ S; n8 [4 W# D7 Q5 F
service mysqld restart( L; Y6 z( _2 @1 \- p
搞定!!7 i8 x, @3 U0 E R% \6 Y
' G2 R5 s Q; a; r9 v. t# {
註: 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 B% N1 p7 a5 J/ D! Y7 ^& O
+ |% g" S2 e% I2 G* r" w5 d& ? ^( _
- \& o! I4 j0 `! s, E N0 ~ 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 即可
- E6 J! Y, {$ A' N4 K: a
1 Y: C q- A J$ t$ @4 N. b: A- {8 A5 Q: @) n5 h. \
[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.: W9 z& T- | u/ F. C5 H: X
說明: 千萬不能照它建議用"UTF8MB4",否則無法成功啟動* l# M6 X( Q& f: [4 Y1 @
K& }; O3 A. y: o(2). _" H% T5 [5 e9 B# g2 d
(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
. H2 u9 ?* L; n5 ]: q& p8 S; RSELECT COUNT(*) FROM common_usergroup WHERE type='special' and system>05 H5 h4 X" [+ H8 J/ B
5 o6 A* f Z: a% {6 h% 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
/ O$ g1 E/ m, f- i g, lSELECT * 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
8 o3 d; U. j9 ?# U. E7 R
6 s2 G& p: X) \因為MySQL 8.0+將system和groups作為了關鍵字,所以不能直接在SQL中將system和groups這兩個詞作為數據庫、數據表、數據表字段中的任意一種使用,如果數據庫名或數據表名或數據表字段名使用了system或groups作為名字,必須使用一對反引號引用起來。寫作`system`或`groups`。2 q9 l5 k" X6 J) y" Y7 E0 n+ q- f3 u$ N
8 }& ?2 O1 i3 Z! A/ i: W1 \6 t) \第一個錯誤需要找到Discuz!目錄中的source\class\table\table_common_usergroup.php,& X5 b$ u$ |' m: a0 ^
將文件中所有的system全部改成`system`,保存後重新上傳到服務器的相同目錄即可。
) h- v" l3 [) d. \. H- Y7 k5 M, ~( T! ^8 C
第二個錯誤需要找到Discuz!目錄下中的source\class\table\table_forum_announcement.php,9 r d3 R# R7 p) e6 r- G9 c
將文件中所有的groups全部改為`groups`,保存後重新上傳到服務器的相同目錄即可。
1 `' p5 w' Q* X( q
! c: c$ Q* w" v @4 k& c- P( `, r如果在MySQL 8+環境下安裝Discuz!,在安裝前需要給install\data\install.sql文件中沒有加引號的所有system逐一添加一對反引號保存重新上傳到服務器的相同目錄,否則也會出現SQL語法錯誤。
3 K1 Z! k# N' d: d3 |9 q p. c1 y# C4 E/ Y. u7 P! W
為了避免語法錯誤,在寫SQL語句時,一定要為所有的數據庫名、數據表名、數據表字段名全部添加一對反引號,像Discuz!這樣的寫法是很不妥的。
; T. L- Q2 [: ]' |7 h1 M以上參考: 升級到 MySQL 8.0+ 後Discuz! 更新緩存時出現SQL語法錯誤
, N+ g; o: e. n9 Q2 } |
|