修復 MySQL 數據庫結構錯誤 – mysql_upgrade升級


不知道是不是每次更新 MySQL 軟件之后都需要執行數據庫升級指令?在我進行過的幾次軟件升級之后,總會在 MySQL 的日志中見到

“[ERROR] Missing system table mysql.proxies_priv; please run mysql_upgrade to create it”之類的錯誤。雖然這個錯誤修復起來很簡單,卻不容易引起注意。
1. 錯誤描述
我在好幾次見到這樣的錯誤提示之后才決定好好看看到底寫了些什么。因為網站運行很正常,就心想應該不怎么重要吧。錯誤提示大致內容如下(已將前導的日期時間略去):

[ERROR] Missing system table mysql.proxies_priv; please run mysql_upgrade to create it
 [ERROR] Native table 'performance_schema'.'events_waits_current' has the wrong structure
 [ERROR] Native table 'performance_schema'.'events_waits_history' has the wrong structure
 [ERROR] Native table 'performance_schema'.'events_waits_history_long' has the wrong structure
 [ERROR] Native table 'performance_schema'.'setup_consumers' has the wrong structure
 [ERROR] Native table 'performance_schema'.'setup_instruments' has the wrong structure
 [ERROR] Native table 'performance_schema'.'setup_timers' has the wrong structure
 [ERROR] Native table 'performance_schema'.'performance_timers' has the wrong structure
 [ERROR] Native table 'performance_schema'.'threads' has the wrong structure
 [ERROR] Native table 'performance_schema'.'events_waits_summary_by_thread_by_event_name' has the wrong structure
 [ERROR] Native table 'performance_schema'.'events_waits_summary_by_instance' has the wrong structure
 [ERROR] Native table 'performance_schema'.'events_waits_summary_global_by_event_name' has the wrong structure
 [ERROR] Native table 'performance_schema'.'file_summary_by_event_name' has the wrong structure
 [ERROR] Native table 'performance_schema'.'file_summary_by_instance' has the wrong structure
 [ERROR] Native table 'performance_schema'.'mutex_instances' has the wrong structure
 [ERROR] Native table 'performance_schema'.'rwlock_instances' has the wrong structure
 [ERROR] Native table 'performance_schema'.'cond_instances' has the wrong structure
 [ERROR] Native table 'performance_schema'.'file_instances' has the wrong structure
 [Note] Event Scheduler: Loaded 0 events
 [Note] /usr/libexec/mysqld: ready for connections.
 Version: '5.5.20-log'  socket: '/var/lib/mysql/mysql.sock'  port: 0

 
有時候可能還會多點兒如下內容:

[ERROR] Incorrect definition of table mysql.proc: expected column 'comment' at position 15 to have type text, found type char(64).

 
一般看到結尾提示個 ready for connections 一般也就沒心思去看前面都提示了什么東西了。我也是有一次在 x86_64 位 CentOS 中的 MySQL 日志中見到了多出來的這個 ERROR 信息才決定好好看看的前面的錯誤提示的。(我是運行在 32 位 CentOS 上的。)
可是見到錯誤提示句子結構都差不多就沒有仔細往前翻,所以我開始還重新安裝了一遍 MySQL 軟件包。后來才看到每次執行
service mysql restart
重起 MySQL服務的時候都會出現這樣的錯誤提示。然后該錯誤提示開頭還說了,讓執行
mysql_upgrade
指令來修復。才恍然大悟,估計是升級了 MySQL 的軟件包,管理數據庫的某些表結構發生了變化,所以還需要升級數據庫的相關表結構
2. 修復

mysql_upgrade -u root -p

 
然后根據提示輸入 mysql 的 root 帳戶密碼,修復過程就可自動運行。此時會有如下形式的提示信息輸出:

mysql_upgrade -u root -p
 Enter password:
 Looking for 'mysql' as: mysql
 Looking for 'mysqlcheck' as: mysqlcheck
 Running 'mysqlcheck' with connection arguments: '--port=3306' '--socket=/var/lib/mysql/mysql.sock'
 Running 'mysqlcheck' with connection arguments: '--port=3306' '--socket=/var/lib/mysql/mysql.sock'
 wp_commentmeta                               OK
 wp_comments                                  OK
 wp_links                                     OK
 wp_options                                   OK
 wp_postmeta                                  OK
 wp_posts                                     OK
 wp_term_relationships                        OK
 wp_term_taxonomy                             OK
 wp_terms                                     OK
 wp_usermeta                                  OK
 wp_users                                     OK
 mysql.columns_priv                                 OK
 mysql.db                                           OK
 mysql.event                                        OK
 mysql.func                                         OK
 mysql.general_log                                  OK
 mysql.help_category                                OK
 mysql.help_keyword                                 OK
 mysql.help_relation                                OK
 mysql.help_topic                                   OK
 mysql.host                                         OK
 mysql.ndb_binlog_index                             OK
 mysql.plugin                                       OK
 mysql.proc                                         OK
 mysql.procs_priv                                   OK
 mysql.servers                                      OK
 mysql.slow_log                                     OK
 mysql.tables_priv                                  OK
 mysql.time_zone                                    OK
 mysql.time_zone_leap_second                        OK
 mysql.time_zone_name                               OK
 mysql.time_zone_transition                         OK
 mysql.time_zone_transition_type                    OK
 mysql.user                                         OK
 Running 'mysql_fix_privilege_tables'...      OK

 
看來每次在 Linux 中升級了 MySQL 軟件包之后都需要進行類似的數據庫升級操作。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM