差異處
這裏顯示兩個版本的差異處。
| 兩邊的前次修訂版 前次修改 下次修改 | 前次修改 | ||
| tech:mysqltips [2020/08/20 10:33] – jonathan_tsai | tech:mysqltips [2022/08/03 15:24] (目前版本) – jonathan | ||
|---|---|---|---|
| 行 1: | 行 1: | ||
| + | ====== MySQL/ | ||
| + | ===== 1. 資料表效能優化 ===== | ||
| + | * 參考 - https:// | ||
| + | - 找出需要優化的資料表 Exp. 資料庫 abc <code sql> | ||
| + | use abc; | ||
| + | select table_name, round(data_length/ | ||
| + | from information_schema.tables | ||
| + | where round(data_free/ | ||
| + | order by data_free_mb; | ||
| + | </ | ||
| + | +----------------+----------------+--------------+ | ||
| + | | table_name | ||
| + | +----------------+----------------+--------------+ | ||
| + | | dwg_files | ||
| + | | pdm_to_erp_log | 24 | 1277 | | ||
| + | | user_use_log | ||
| + | +----------------+----------------+--------------+ | ||
| + | 3 rows in set (0.006 sec) | ||
| + | </ | ||
| + | - 針對呈現出來的 Table 進行優化 <code sql> | ||
| + | OPTIMIZE TABLE dwg_files, pdm_to_erp_log, | ||
| + | </ | ||
| + | +--------------------------+----------+----------+-------------------------------------------------------------------+ | ||
| + | | Table | Op | Msg_type | Msg_text | ||
| + | +--------------------------+----------+----------+-------------------------------------------------------------------+ | ||
| + | | abc.dwg_files | ||
| + | | abc.dwg_files | ||
| + | | abc.pdm_to_erp_log | optimize | note | Table does not support optimize, doing recreate + analyze instead | | ||
| + | | abc.pdm_to_erp_log | optimize | status | ||
| + | | abc.user_use_log | ||
| + | | abc.user_use_log | ||
| + | +--------------------------+----------+----------+-------------------------------------------------------------------+ | ||
| + | 6 rows in set (31.340 sec) | ||
| + | </ | ||
| + | - 查看 / | ||
| + | |||
| + | ===== 2. 設定與查詢週期定時執行程序 ===== | ||
| + | * 參考 - https:// | ||
| + | - 查看現有排程 <code sql> | ||
| + | show events; | ||
| + | </ | ||
| + | +-----------+-------------------------------------------------------------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+---------------------+---------+------------+----------------------+----------------------+--------------------+ | ||
| + | | Db | Name | Definer | ||
| + | +-----------+-------------------------------------------------------------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+---------------------+---------+------------+----------------------+----------------------+--------------------+ | ||
| + | | abc | SE同步刪除1個月以上的紀錄 | ||
| + | | abc| 刪除1個月以上的curl資料 | ||
| + | : | ||
| + | </ | ||
| + | - 顯示詳細排程內容 Exp. 刪除1個月以上的curl資料 <code sql> | ||
| + | SELECT * FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_NAME=' | ||
| + | </ | ||
| + | +---------------+--------------+----------------------------------+----------------+-----------+------------+-------------------------------------------------------------------------------------+------------+------------+----------------+----------------+-------------------------------------------------------------------------------------------+---------------------+---------------------+---------+---------------+---------------------+---------------------+---------------------+---------------+------------+----------------------+----------------------+--------------------+ | ||
| + | | EVENT_CATALOG | EVENT_SCHEMA | EVENT_NAME | ||
| + | +---------------+--------------+----------------------------------+----------------+-----------+------------+-------------------------------------------------------------------------------------+------------+------------+----------------+----------------+-------------------------------------------------------------------------------------------+---------------------+---------------------+---------+---------------+---------------------+---------------------+---------------------+---------------+------------+----------------------+----------------------+--------------------+ | ||
| + | | def | abc | 刪除1個月以上的curl資料 | ||
| + | +---------------+--------------+----------------------------------+----------------+-----------+------------+-------------------------------------------------------------------------------------+------------+------------+----------------+----------------+-------------------------------------------------------------------------------------------+---------------------+---------------------+---------+---------------+---------------------+---------------------+---------------------+---------------+------------+----------------------+----------------------+--------------------+ | ||
| + | 1 row in set (0.001 sec) | ||
| + | </ | ||
| + | - 建立新的排程 Exp. 針對特定 Table 每周日中午 12:07 進行優化 <code sql> | ||
| + | CREATE EVENT 優化LOG型資料表 | ||
| + | ON SCHEDULE EVERY 7 DAY STARTS ' | ||
| + | DO | ||
| + | | ||
| + | </ | ||
| + | SHOW events; | ||
| + | </ | ||
| + | +-----------+-------------------------------------------------------------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+---------------------+---------+------------+----------------------+----------------------+--------------------+ | ||
| + | | Db | Name | Definer | ||
| + | +-----------+-------------------------------------------------------------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+---------------------+---------+------------+----------------------+----------------------+--------------------+ | ||
| + | | abc | SE同步刪除1個月以上的紀錄 | ||
| + | | abc | 優化LOG型資料表 | ||
| + | : | ||
| + | </ | ||
| + | |||
| + | ===== 3. 出現異常訊息 - [ERROR] mysqld: Table ' | ||
| + | * 參考 - https:// | ||
| + | * 對 database : stats 進行修復 <cli> | ||
| + | mysqlcheck -r --databases stats --use-frm | ||
| + | </ | ||
| + | : | ||
| + | : | ||
| + | 220803 15:11:48 [ERROR] mysqld: Table ' | ||
| + | 220803 15:13:10 [Note] Found 6676 of 0 rows when repairing ' | ||
| + | 220803 15:13:10 [Note] Found 813 of 0 rows when repairing ' | ||
| + | : | ||
| + | 220803 15:13:11 [Note] Found 517 of 0 rows when repairing ' | ||
| + | 220803 15:13:11 [Note] Found 1013 of 0 rows when repairing ' | ||
| + | </ | ||
| + | |||
| + | {{tag> | ||