掃二維碼與項目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
當(dāng)您的網(wǎng)站因數(shù)據(jù)庫錯誤而損壞或無法訪問時,您可能需要檢查或修復(fù) MySQL 中的數(shù)據(jù)庫或表。在這種情況下,您可以使用 mysqlcheck 工具檢查并修復(fù)損壞的表或數(shù)據(jù)庫。mysqlcheck 是一個維護工具,允許您通過命令行界面檢查、修復(fù)、分析和優(yōu)化 MySQL 表。使用 mysqlcheck 的最佳功能之一是您可以在實時網(wǎng)站上執(zhí)行數(shù)據(jù)庫維護,而無需停止 MySQL 服務(wù)。

陽明網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,陽明網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為陽明上千余家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的陽明做網(wǎng)站的公司定做!
在這篇文章中,我們將解釋如何檢查/修復(fù) MySQL 數(shù)據(jù)庫和表。
mysqlcheck 命令行工具的基本語法如下所示:
mysqlcheck [OPTION] DATABASENAME TABLENAME -u root -p
下面顯示了可以與 mysqlcheck 一起使用的每個選項的簡要說明:
有時,您可能需要檢查特定數(shù)據(jù)庫中的特定表。在這種情況下,您可以使用以下語法:
mysqlcheck -c db-name table-name -u root -p
例如,要檢查 class 數(shù)據(jù)庫中的 students 表,請運行以下命令:
mysqlcheck -c class students -u root -p
您將獲得以下輸出:
class.students OK
如果要檢查特定數(shù)據(jù)庫中的所有表,請使用以下語法:
mysqlcheck -c db-name -u root -p
例如,要檢查 class 數(shù)據(jù)庫中的所有表,請運行以下命令:
mysqlcheck -c class -u root -p
您應(yīng)該得到以下輸出:
Enter password:
class.teacher OK
class.students OK
class.peon OK
您可以使用以下命令檢查所有表和所有數(shù)據(jù)庫:
mysqlcheck -c -u root -p --all-databases
輸出:
Enter password:
class.teacher OK
class.students OK
class.peon OK
guest.MyGuests OK
movies.hotstar OK
mysql.columns_priv OK
mysql.component OK
mysql.db OK
mysql.default_roles OK
mysql.engine_cost OK
mysql.func OK
mysql.general_log OK
mysql.global_grants OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.password_history OK
mysql.plugin OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.role_edges OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
您還可以使用以下命令優(yōu)化所有表和所有數(shù)據(jù)庫:
mysqlcheck -o root -p --all-databases
輸出:
Enter password:
class.teacher
note : Table does not support optimize, doing recreate + analyze instead
status : OK
class.students
note : Table does not support optimize, doing recreate + analyze instead
status : OK
class.peon
note : Table does not support optimize, doing recreate + analyze instead
status : OK
guest.MyGuests
note : Table does not support optimize, doing recreate + analyze instead
status : OK
movies.hotstar
note : Table does not support optimize, doing recreate + analyze instead
status : OK
mysql.columns_priv
在上面的輸出中,您應(yīng)該看到“ Table does not support optimize ”,這意味著 InnoDB 表不支持此選項。
修復(fù) MySQL 數(shù)據(jù)庫
要修復(fù) class 數(shù)據(jù)庫中的 teacher 表,請運行以下命令:
mysqlcheck -r class teacher -u root -p
輸出:
mysqlcheck -r class teacher -u root -p
Enter password:
class.teacher OK
要修復(fù) class 和 movies 數(shù)據(jù)庫中的所有表,請運行以下命令:
mysqlcheck -r --databases class movies -u root -p
輸出:
Enter password:
class.teacher OK
class.students OK
class.peon OK
movies.hotstar OK
如果要檢查和修復(fù)所有數(shù)據(jù)庫中的所有表,請運行以下命令:
mysqlcheck --auto-repair --all-databases -u root -p
輸出:
Enter password:
class.teacher OK
class.students OK
class.peon OK
guest.MyGuests OK
movies.hotstar OK
mysql.columns_priv OK
mysql.component OK
mysql.db OK
mysql.default_roles OK
mysql.engine_cost OK
mysql.func OK
mysql.general_log OK
mysql.global_grants OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.password_history OK
mysql.plugin OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.role_edges OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info 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
注意:默認(rèn)情況下,InnoDB 存儲引擎不支持修復(fù)。在這種情況下,您需要將 MySQL 存儲引擎從 InnoDB 更改為 MyISAM。
在這篇文章中,我們解釋了如何使用 mysqlcheck 命令行工具檢查和修復(fù) MySQL 中的表。

我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流