52AV手機A片王|52AV.ONE

標題: mysqld 升級到8以上遇到的問題 [打印本頁]

作者: coav4u    時間: 2021-3-14 13:06
標題: mysqld 升級到8以上遇到的問題
(1)  Y. j: u1 }& \( \1 w
php連到mysql出現2行errors : (discuz網頁出現的是連接到mysql錯誤表格,需自行寫一隻連接mysql的php程式來測試)6 p* x! I7 [3 a8 s9 c# j
2 O; q4 d  W0 w* S% T: g
mysqli_real_connect(): Server sent charset (255) unknown to the client. Please, report to the developers( c# `- J/ z) H1 o1 h5 ~/ E( t
mysqli_real_connect(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers( t7 M& K3 q5 J8 R
原因:

# k5 A' [7 \' r6 K) @/ O8 T6 E在MySQL 8.0.21中,caching_sha2_password是默認的身份驗證插件,而不是以往的mysql_native_password。所以和php不相容。可以降級php,也可以修改MySQL的配置。 吾人決定修改MySQL的配置:
8 W3 O8 ]1 O0 g2 I' Rvi /etc/my.cnf  加入下列:
$ h$ V) Y9 R; ^4 S) v9 W: V[mysqld]
. X* ?7 ]  V% Y- @- |0 ]1 X% M! P. a3 K# ~
character-set-server=utf88 m! v7 V4 p1 a( F. v) G/ y9 _4 b
default_authentication_plugin=mysql_native_password2 u1 W7 Z2 l2 A7 e6 Z6 q* L
validate_password.policy=LOW
, E% j: n; a) Z& ~
[mysql]3 y. W7 T5 t" |, k3 c
default-character-set=utf8
. o+ F: e3 r3 ~% Q7 K2 |) J0 A  r  y% F' t, C; t
[client]2 u9 W+ t2 L2 k* w# K5 L/ t5 a
default-character-set=utf8$ V& Z2 j% M  u% D- R
; O7 ^7 M6 g! X& F
然後重啟mysqld; j4 u& l, G& e* W+ b
service mysqld restart

+ m! Y0 b7 T9 q: V3 s3 b; R

/ H9 E3 b6 T. k1 C* x8 {- @% n重啟後可能須做下列動作:
4 Z8 u$ N4 A( W5 Hmysql -u roor -p  
4 g* K% F! p2 p0 U# P* T1 U. X0 rSHOW VARIABLES LIKE 'validate_password%';
, T/ R$ E: [6 i) Y2 R$ j" vSET GLOBAL validate_password_policy=LOW;ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密碼';搞定!!1 q7 @/ s! x* Q( l
* l4 m- P4 _1 q& |1 s. G# o$ _
註: mysqld啟動時,在/var/log/mysql/mysqld.log紀錄著:
註: 可以先寫支php程式以測試 ~~~
" G( [3 v; |& U3 H: O
  1. <?
    # c& k' Z* Q6 e3 G0 b2 Q& Z
  2. $hostname = "x.x.x.x";
    1 H! K/ Z/ K' P8 f' x% A/ v# s
  3. $database = "db_name";' l* F* d. K. y5 O2 z$ X
  4. $username = "user_name";
    . J% W0 v# k) Z( I
  5. $password = "pwd";
    7 w1 D1 y! b) \: O* ^

  6. ( p9 I9 F4 Q9 M) K
  7. $conn = mysqli_connect($hostname, $username, $password,$database) or trigger_error(mysql_error(),E_USER_ERROR);- w+ _( o4 y  @7 a9 \; ]' G+ ~
  8. mysqli_query($conn ,"SET NAMES utf8");
    7 h7 l; D3 d# ~7 x9 V, A

  9. % z7 r; v" X2 Z
  10. $sql = "select count(*) as total from " .  "table_name";
      h' V6 l. ^' L% |4 z( n5 D
  11. $rec = mysqli_fetch_assoc(mysqli_query( $conn,$sql));! }+ \; Y* O3 V' b9 o
  12. echo $rec['total'];$ f4 U+ G( H# s
  13. mysqli_close($conn);4 D( Q  H+ t& s3 i3 `# X
  14. ?>
複製代碼
[hide=d100000000000000000000,999999999999]於video1主機下 /test/connectmysql8.php[/hide]
6 z( h, z+ B; o, O# z, T% ?* J; a
; O7 I2 [9 {/ Z0 k- `1 r
當php 7.2.24  connect to mysql server,出現 :
  1. PHP Fatal error:  Uncaught Error: Call to undefined function mysqli_connect() in /test/connectmysql8.php:9
    - o$ b. h" y/ x# A
  2. Stack trace:8 d- M+ \0 U( M7 H) @
  3. #0 {main}0 a9 o5 x  t- Z; J8 B
  4.   thrown in /test/connectmysql8.php on line 98 d4 U# ^4 U' J+ y
  5. % ^* B! O' p6 x( B5 w, m* @
  6. Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /test/connectmysql8.php:9% _  r6 A" |" i2 v. N3 s
  7. Stack trace:5 V& M! @) o. ~, O
  8. #0 {main}
    4 r3 X" r4 u+ S3 G% X* Q
  9.   thrown in /test/connectmysql8.php on line 9
複製代碼
這是版本相依的問題,只要 yum install php-mysqlnd  或 yum install php-mysqli 即可* e- M& _$ L1 O& [, y

( c- K6 y  w0 o: {/ Z, F! E& F
[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.* z2 K2 Z! [" G
說明: 千萬不能照它建議用"UTF8MB4",否則無法成功啟動
; A/ u+ {7 g( c1 U  c& ^
, D: W2 E9 L0 w3 U+ e& v" ^( g8 {(2)
3 z* \* Y( b5 E% C& @4 G5 ^  }(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: Z$ b/ S* \: x6 h& t+ q
SELECT COUNT(*) FROM common_usergroup WHERE type='special' and system>07 C* g* d: h, r! d& G+ J

$ i$ [5 ]: B! V  o(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
% u1 e/ E% X) @  {6 a$ XSELECT * 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 11 Z4 R1 ~, l0 r  ]* y- K
2 y8 y. _. L& l3 j' i% N7 r
因為MySQL 8.0+將system和groups作為了關鍵字,所以不能直接在SQL中將system和groups這兩個詞作為數據庫、數據表、數據表字段中的任意一種使用,如果數據庫名或數據表名或數據表字段名使用了system或groups作為名字,必須使用一對反引號引用起來。寫作`system`或`groups`。
- H5 J9 W- E( K( j" t; L9 v6 K, o8 G# l  W3 E( h/ m2 J+ [6 M3 Y
第一個錯誤需要找到Discuz!目錄中的source\class\table\table_common_usergroup.php,' U8 L+ t3 @0 n/ c/ Z3 f, K0 E
將文件中所有的system全部改成`system`,保存後重新上傳到服務器的相同目錄即可。
. _0 _$ @& J$ |4 B4 X9 K4 |" N! ~3 b6 |4 G7 B, @. k0 H
第二個錯誤需要找到Discuz!目錄下中的source\class\table\table_forum_announcement.php,, X- v3 w0 l5 R6 i1 c1 e
將文件中所有的groups全部改為`groups`,保存後重新上傳到服務器的相同目錄即可。
" ~6 c% p1 ^5 U$ r/ n, F5 w
( Y- }) P( |1 E- Z' m* _如果在MySQL 8+環境下安裝Discuz!,在安裝前需要給install\data\install.sql文件中沒有加引號的所有system逐一添加一對反引號保存重新上傳到服務器的相同目錄,否則也會出現SQL語法錯誤。* I2 j6 H8 k7 N4 g1 @+ }
5 n" [5 @# h1 i) w3 E. A3 v
為了避免語法錯誤,在寫SQL語句時,一定要為所有的數據庫名、數據表名、數據表字段名全部添加一對反引號,像Discuz!這樣的寫法是很不妥的。$ x, D9 e8 b" G6 V9 C0 @! E1 P
以上參考:   升級到 MySQL 8.0+ 後Discuz! 更新緩存時出現SQL語法錯誤
$ z  n2 }7 [. a! Z: h  Q" \+ H

( x9 Y% F+ Z5 |
: ]  h9 d, m3 x4 O8 E( k9 q/ m, a0 G+ W8 _1 i7 |: w( L: |. ?1 N6 G
  d, k& f9 V* r' F4 @/ U* n- P1 w





歡迎光臨 52AV手機A片王|52AV.ONE (https://nhkie.com/) Powered by Discuz! X3.2