apple 2012-1-10 03:25
設定排程讓MySQL 自動最佳化資料表 (optimize)
當發現網站運作的速度越來越慢, 主要原因應該是資料越來越多, Database 也開太多,所以要來為所有 DB 做 Optimize 和 Repair 的動作. <div><br></div><div>在 Mysql 5 以上就有提供 mysqlcheck 這樣功能的程式可以用 ~~ 用法如下:</div><div>[quote]</div><div>/usr/bin/mysqlcheck -opr -uroot -p --databases discuz</div><div>[/quote]</div><div>輸入密碼之後就可以最佳化 discuz 的資料庫</div><div><br></div><div>如果要最佳化所有的資料庫...可以使用底下語法:</div><div>[quote]</div><div>/usr/bin/mysqlcheck -acor -uroot -p --all-database</div><div>[/quote]</div><div># 此命令就可以 Check 所有 MyISAM 的 Table, 非 MyISAM 會出現 "Table does not support optimize, doing recreate + analyze instead" 自動略過</div><div><br></div><div>-a = Analyse given tables.<br> -c = Check table for errors<br> -o = Optimise table<br> -r = Can fix almost anything except unique keys that aren't unique<div style="overflow-x: hidden; overflow-y: hidden; text-decoration: none; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-image: initial; "><br></div><div style="overflow-x: hidden; overflow-y: hidden; text-decoration: none; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-image: initial; ">如果要最佳化所有的資料庫...並且自動代入MySQL密碼...可以使用底下語法:<br>[quote]</div></div><div style="overflow-x: hidden; overflow-y: hidden; text-decoration: none; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-image: initial; ">/usr/bin/mysqlcheck -acor -uroot --password='12345678' --all-database</div><div style="overflow-x: hidden; overflow-y: hidden; text-decoration: none; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-image: initial; ">[/quote]</div><div style="overflow-x: hidden; overflow-y: hidden; text-decoration: none; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-image: initial; "><br></div><div style="overflow-x: hidden; overflow-y: hidden; text-decoration: none; border-top-width: medium; border-right-width: medium; border-bottom-width: medium; border-left-width: medium; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-color: initial; border-image: initial; ">再來就可以使用自動排程下去執行囉~~</div>