|
|
(1)
' {" q2 K* R! m3 yphp連到mysql出現2行errors : (discuz網頁出現的是連接到mysql錯誤表格,需自行寫一隻連接mysql的php程式來測試)
0 w7 i8 \# f9 }
; `3 e$ ?( {( H }+ m* Jmysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers
R5 w9 O# `1 f' Q: i wmysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers% y% W" S* A% L. s4 n& ?* V6 O, E
原因:
, g' \$ X- U) M在MySQL 8.0.21中,caching_sha2_password是默認的身份驗證插件,而不是以往的mysql_native_password。所以和php不相容。可以降級php,也可以修改MySQL的配置。 吾人決定修改MySQL的配置:
9 D' o1 F) M8 F: N3 \" t s' Hvi /etc/my.cnf 加入下列:4 v* l6 Q% b/ z$ e5 X
[mysqld]
* U: x, P5 _: y0 L/ s/ Z9 U
6 Z5 x: c$ w7 w5 S2 z9 N% v" Echaracter-set-server=utf8
5 T( d1 J: q, O3 U% ^6 l) Ddefault_authentication_plugin=mysql_native_password
" x& F) x7 @: ~8 a& g# Qvalidate_password.policy=LOW, |2 j+ e- i7 P
[mysql]
/ G* n/ |0 T0 Q5 e* edefault-character-set=utf80 v7 P3 L& l, Z) m" e/ g# h- J
# t t" C0 r* v
[client]! m3 R. n, N, Q; e
default-character-set=utf8
+ Q" l( D. r: X& N% @% v# L5 q$ F
( R6 {; h) {+ A8 w然後重啟mysqld: c/ g, k+ O2 {) y
service mysqld restart
: _( Z: v2 P6 p8 a6 O I1 R! Z( ?- ?( r* K
重啟後可能須做下列動作:
# s D2 ?7 e' f; G6 Bmysql -u roor -p
$ ]3 d7 d# \" i6 J0 l* B$ nSHOW VARIABLES LIKE 'validate_password%';' t$ d; t D$ G' g
SET GLOBAL validate_password_policy=LOW;ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密碼';搞定!!
; P M0 o6 @7 P8 e+ @) w0 K; g+ F' {! f' h
註: mysqld啟動時,在/var/log/mysql/mysqld.log紀錄著:註: 可以先寫支php程式以測試 ~~~
6 ~% k; ~* R" a5 q: d- <?
* x- V7 j) t; g, e5 w - $hostname = "x.x.x.x";7 ?7 [. O2 D; r( O8 I
- $database = "db_name";
& _$ s3 q: h9 {, m# I B `0 f6 i+ C - $username = "user_name";
U) s% U0 G, j5 A& |, U& ~ - $password = "pwd";5 b- ~% r& B% R+ m( ~# r/ F
% t" `8 \. u' j# A7 t1 n$ P" ]- $conn = mysqli_connect($hostname, $username, $password,$database) or trigger_error(mysql_error(),E_USER_ERROR);4 l' g; H4 n7 q
- mysqli_query($conn ,"SET NAMES utf8"); p+ I) v7 {/ Z# F
' K% Z( J" i/ C/ t7 I. [4 L4 S- $sql = "select count(*) as total from " . "table_name";
$ @$ y' ~6 h' I- H, ^% ] - $rec = mysqli_fetch_assoc(mysqli_query( $conn,$sql));% O. R* E- _+ ~3 d! n
- echo $rec['total'];# `0 T( m3 \4 F% w; j
- mysqli_close($conn);% x6 v, G5 W* Y& F1 q% ^
- ?>
複製代碼遊客,本帖隱藏的內容需要積分高於 999999999999 才可瀏覽,您當前積分為 0
- S' J4 [* Z5 @6 u3 x
4 N3 f5 P4 q3 Y* G( y6 c& A% _ I4 E$ X# B0 z$ {9 a/ ^: b" ~' \" @0 ?
當php 7.2.24 connect to mysql server,出現 : - PHP Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /test/connectmysql8.php:9
( B* r9 _! r; p - Stack trace:
+ r$ B- a- R8 X* q5 } - #0 {main}
. R: r r& r, w" A; } J1 ~ - thrown in /test/connectmysql8.php on line 9: k! b$ J4 q8 `/ r
- 5 A0 P. P/ W) G; O! U% ~! d& B' G
- Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /test/connectmysql8.php:9
: B2 h% B4 t% I7 p1 |2 @' l* x$ v; u - Stack trace:
8 [1 c7 ]7 d* e8 ^5 K - #0 {main}: K- F8 |0 V3 G S s( q5 T# K. g
- thrown in /test/connectmysql8.php on line 9
複製代碼 這是版本相依的問題,只要 yum install php-mysqlnd 或 yum install php-mysqli 即可
, _8 ]5 R) v/ M% v/ j! T- G5 l+ d% Q& l9 ^' H5 D
* \2 v" j0 b5 h$ b) \; e[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.
/ F1 G& ~- v7 W; R/ s( t! X說明: 千萬不能照它建議用"UTF8MB4",否則無法成功啟動) W: l" @6 A1 D4 r2 B
9 U. h0 _9 R+ X7 D
(2)
* U3 ~* W) S* l( H' n# ^(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
6 A, j& k0 F4 K0 Q* ~1 o+ F2 rSELECT COUNT(*) FROM common_usergroup WHERE type='special' and system>0, V( z4 v8 y! ~# b3 b2 z! [
6 Y/ }2 v; t S2 R( T" a+ J
(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! C0 _) h3 W$ m7 P
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
* s z/ o. _ \! |( F4 }" M3 F& x7 r, W; I( m
因為MySQL 8.0+將system和groups作為了關鍵字,所以不能直接在SQL中將system和groups這兩個詞作為數據庫、數據表、數據表字段中的任意一種使用,如果數據庫名或數據表名或數據表字段名使用了system或groups作為名字,必須使用一對反引號引用起來。寫作`system`或`groups`。
% o3 j/ K, h6 U* v! v w/ O8 i g9 h7 ]
第一個錯誤需要找到Discuz!目錄中的source\class\table\table_common_usergroup.php,. U+ J( U6 a' G
將文件中所有的system全部改成`system`,保存後重新上傳到服務器的相同目錄即可。5 ?( l9 q, i5 L( A3 ~: {! n5 K
, k- _ t: _ X- [/ R, ]第二個錯誤需要找到Discuz!目錄下中的source\class\table\table_forum_announcement.php,2 C/ d Y# n/ Z% ?
將文件中所有的groups全部改為`groups`,保存後重新上傳到服務器的相同目錄即可。
|2 V) b" b. P5 u- @
8 L5 E, u7 {$ x% I" J( D" O如果在MySQL 8+環境下安裝Discuz!,在安裝前需要給install\data\install.sql文件中沒有加引號的所有system逐一添加一對反引號保存重新上傳到服務器的相同目錄,否則也會出現SQL語法錯誤。
4 u8 n# Z2 j; Z# s9 k. g6 [' U8 o- h1 g0 a- a) k! s. G
為了避免語法錯誤,在寫SQL語句時,一定要為所有的數據庫名、數據表名、數據表字段名全部添加一對反引號,像Discuz!這樣的寫法是很不妥的。
) n- b3 U3 X7 E9 a2 W以上參考: 升級到 MySQL 8.0+ 後Discuz! 更新緩存時出現SQL語法錯誤% V! V( s5 ~" j' y! s" s, J; W
$ ]! N1 `' s; e: w2 v2 m, x
( ^7 x& ?: e2 K- ^7 r7 [2 b2 ?
) h8 t2 Q1 ^) t1 H4 t% X% H7 N
- v: m0 T. A; g2 M8 n |
|
|