
我有一個 mysql 資料庫,以前運行得很好,但現在啟動速度非常慢。當我輸入時
$> mysql -u foo bar
在收到提示之前,我收到以下常見訊息大約 30 秒:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
當然,我嘗試了一下,速度快了很多:
$> mysql -u foo bar -A
但為什麼我在正常啟動時需要等待這麼長時間?這不是一個非常大的資料庫(編輯:<10 MB),而且資料似乎沒有損壞(啟動後一切看起來都很好)。我沒有其他客戶端同時連接到 mysql 伺服器(命令僅顯示一個進程show full processlist
)並且我已經重新啟動了該mysqld
服務。
這是怎麼回事 ?
答案1
我認為問題源於自動重新散列功能
我今天嘗試了這個
在 mysql 提示字元下,我輸入
mysql> desc outbound_
我點擊標籤兩次並得到以下信息
mysql> desc outbound_
outbound_call_id outbound_log.ext outbound_log.template_id
outbound_log outbound_log.failed outbound_log.transfer_connected
outbound_log.DealerVoiceProviderType outbound_log.icallclick_alert outbound_log.transfer_duration
outbound_log.VoipCallStatusType outbound_log.isService outbound_log.transfer_ended
outbound_log.VoipTransferStatusType outbound_log.lead_id outbound_log.transfer_ext
outbound_log.call_duration outbound_log.outbound_log_id outbound_log.transfer_phone
outbound_log.call_ended outbound_log.phone outbound_log.transfer_started
outbound_log.call_started outbound_log.postback outbound_log.transfer_status
outbound_log.call_type outbound_log.recording_url outbound_log.vehicle_id
outbound_log.called outbound_log.remote_call_id outbound_log_id
outbound_log.callnote_synced outbound_log.sales_id
outbound_log.dealer_id outbound_log.scheduled
mysql> desc outbound_
每個資料庫和表格都出來供我選擇
顯然,mysql客戶端要讀取information_schema
資料庫。如果您的 mysql 實例包含大量 InnoDB 表,我可以看到auto-rehash
mysql 用戶端停止運行,直到它可以讀取information_schema
資料庫。
答案2
將以下內容新增至您的 [mysql] (注意它不以 d 結尾),它將大大加快您的回應時間:
no-auto-rehash
答案3
謝謝大家,我找到問題的答案了。無法存取資料庫中的表之一:
mysql> show columns from foo;
ERROR 1033 (HY000): Incorrect information in file: './db/foo.frm'
foo.frm
無法再讀取關聯的檔案。
$> cat foo.frm
cat: foo.frm: input/output error
磁碟故障:/ Mysql 啟動時需要很長時間,因為它嘗試存取該文件中的資料。