|
|
tid=187560&(1)
: t$ k) w" [( w( yphp連到mysql出現2行errors : (discuz網頁出現的是連接到mysql錯誤表格,需自行寫一隻連接mysql的php程式來測試)
n- M/ g3 O1 d. i! }8 F; t. ^2 ?$ V7 {/ m4 ]: D. Y
mysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers
/ r7 ?4 F& F4 \# emysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers$ W8 B# v' w# r, M, @& o
原因:6 N. }! d, q7 a
在MySQL 8.0.21中,caching_sha2_password是默認的身份驗證插件,而不是以往的mysql_native_password。所以和php不相容。可以降級php,也可以修改MySQL的配置。 吾人決定修改MySQL的配置:6 [2 q) L$ S+ \6 Z( I j. J
vi /etc/my.cnf 加入下列:$ Z/ C- d+ D# `: O3 j* c9 T, S
[mysqld]0 D! i! o5 e0 P# b5 D/ m$ P+ e- v" i! R/ _
# F" K* Q# w; O4 @" S
character-set-server=utf8- P/ N3 ]4 E9 L- X/ ^* ~/ L( l
default_authentication_plugin=mysql_native_password
0 S$ D: S8 q; x9 c: J/ U
+ j: _; q: q2 I, X' `[mysql]' k9 o0 [* a3 ~4 M$ b; z' k7 g$ \
default-character-set=utf8
' j( h; C) t" q! b$ F' n! s% I; C4 E& g# t4 I, o5 @
[client]: [3 i8 Z8 P' U( L3 d
default-character-set=utf8
o1 U& R8 }' X1 e! ?3 Z4 p; s4 u6 o" y' r! v; ^
然後重啟mysqld4 [( D; x( d3 t) d' }' L, d
service mysqld restart
! p' R( P& L$ _/ _搞定!!
7 U% \) Z, k5 A6 P) F) V9 b1 `$ \ q# `7 S" ]: }* E( X
註: 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 5 E6 {3 A/ `8 G
6 s6 {* E f2 Z0 [
! ~& u, G8 W9 |$ z: ~! t. g當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 即可
4 f& P* N& [! `. @$ e; y3 |" d9 [( U* c0 O* T7 x+ G8 k
, L: A. q. {) I
[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.
4 P* h# C" A6 {- _4 \+ a$ @' P( u說明: 千萬不能照它建議用"UTF8MB4",否則無法成功啟動1 t( {! q; I3 m0 \: t6 w t- |; H. }
( n6 `% h2 H& n8 ~2 }, U& P( j
(2)! x6 j$ x: c' E7 A7 C
(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 17 F4 e3 \% I, ]
SELECT COUNT(*) FROM common_usergroup WHERE type='special' and system>0& P4 h/ \. y* _
# M6 U' w! }& @9 x(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 18 o& N4 D! t7 S
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) e' o2 C- A& V) V- f. w- x) q& d
; B3 q) T9 V* }5 T5 ]/ S! A
因為MySQL 8.0+將system和groups作為了關鍵字,所以不能直接在SQL中將system和groups這兩個詞作為數據庫、數據表、數據表字段中的任意一種使用,如果數據庫名或數據表名或數據表字段名使用了system或groups作為名字,必須使用一對反引號引用起來。寫作`system`或`groups`。
: {# R$ Z' ]( _3 p; T3 j4 a$ g. U1 P3 `
% w3 c1 u) E, |第一個錯誤需要找到Discuz!目錄中的source\class\table\table_common_usergroup.php,
n, A/ u9 {$ i+ i. B2 a$ {將文件中所有的system全部改成`system`,保存後重新上傳到服務器的相同目錄即可。$ }' D+ b0 Z0 O6 k# k+ I
: X3 f5 l& H: g! `& b# G) t第二個錯誤需要找到Discuz!目錄下中的source\class\table\table_forum_announcement.php," G- R$ ^! a+ z# [2 H3 e0 Q
將文件中所有的groups全部改為`groups`,保存後重新上傳到服務器的相同目錄即可。8 O! n+ E% P$ ?* x, h* D
& `0 }$ M: Z% w z& l& Y K$ m如果在MySQL 8+環境下安裝Discuz!,在安裝前需要給install\data\install.sql文件中沒有加引號的所有system逐一添加一對反引號保存重新上傳到服務器的相同目錄,否則也會出現SQL語法錯誤。
6 i$ A3 O l. s) w: V1 x
/ `7 i( V& ^5 i# P7 b9 }為了避免語法錯誤,在寫SQL語句時,一定要為所有的數據庫名、數據表名、數據表字段名全部添加一對反引號,像Discuz!這樣的寫法是很不妥的。
B+ V$ @) n C* [1 G+ k' e以上參考: 升級到 MySQL 8.0+ 後Discuz! 更新緩存時出現SQL語法錯誤
5 h/ C4 ]3 a0 \6 M6 d, G |
|