Check and Optimize MySQL Database Automatically with Crontab/Cron檢查和優化MySQL數據庫自動Crontab /玉米
MySQL is a very popular free yet powerful database system. MySQL是一個非常受歡迎的免費而強大的數據庫系統。 But even in great databases, the tables may get fragmented with overhead due to continuous update, or delete and insert operation on data stored in database.但是,即使是在偉大的數據庫,表可能會分散,間接由於不斷更新,或刪除和插入操作的數據存儲在數據庫中。 Beside, it’s also possibility that the databases may get corrupted.旁邊,這也是可能的數據庫可能會損壞。 Thus, performing health check on database and optimize MySQL server regularly is an important task.因此,從事健康檢查的數據庫和優化MySQL服務器經常是一項重要任務。
It’sa bit troublesome if the database administrators have to login to the server or launching the phpMyAdmin to optimize the databases one by one or table by table manually.這是一個有點麻煩,如果數據庫管理員已經登錄到服務器或發起phpMyAdmin優化一個數據庫由一個或表的表手動。 Sometimes DB admin may simply forgets to do the job or set the frequency of optimization to lesser times.有時,數據庫管理員可能只是忘記做的工作或設置的頻率較低優化倍。 It’s recommended that every tables in MySQL databases are checked at least once a day on a busy server.它的每一個建議,表在MySQL數據庫進行檢查至少一次,每天在繁忙的服務器上。
It’s possible to automate the optimization of MySQL process by using crontab function in Linux/Unix/CentOS/FreeBSD.這有可能自動優化過程中的MySQL使用crontab功能在Linux / UNIX / CentOS / FreeBSD的。 The cron job to check and optimize MySQL databases can be created by using mysqlcheck client utility comes MySQL installation.該計劃作業,檢查和優化MySQL的數據庫,可以創建使用mysqlcheck客戶端工具來自MySQL的安裝。 mysqlcheck client can checks, repairs, optimizes, and analyzes tables in MySQL database. mysqlcheck客戶可以檢查,維修,優化,分析表中MySQL數據庫。
To create a new cron job, login to the server as root or any other user, and then edit the crontab file (in most operating system, crontab -e will open crontab file in default text editor) to add in the following line of text.要創建新的計劃作業,登錄到服務器作為根或任何其他用戶,然後編輯crontab文件(在大多數操作系統, crontab娥將打開crontab文件中預設的文字編輯器)中添加下面一行文字。 For users using cPanel, click on “Cron job” where you can set up crontab at daily, hourly and other interval.對於用戶使用的cPanel ,點擊“玉米工作”您可以在這裡設立了crontab在每天,每小時和其他間隔。 Experience webmasters can also set up a crontab file in rc.hourly or rc.daily or other cron directory.網站管理員的經驗也可以設立一個crontab文件中rc.hourly或rc.daily或其他玉米目錄。 Note that if you login as a MySQL or normal user with no access privileges to all database, it’s not possible to optimize all databases, unless user ID and password for root is specified as in example below.請注意,如果您登錄作為一個MySQL或普通用戶沒有訪問權限的所有數據庫,它是不可能的優化所有數據庫,除非用戶ID和密碼的根被指定為在以下範例。
0 1 * * * mysqlcheck -Aao –auto-repair -u root -p[password] > /dev/null 0 1 * * * mysqlcheck ,氧化鋁,汽車修理聚氯乙烯根一p [密碼] “的/ dev /無效
The above statement has the syntax similar to “mysqlcheck [options] –all-databases”, where –all-databases parameter is the default action is no databases is specified thus can be omitted.上述聲明的語法類似“ mysqlcheck [選項] ,所有數據庫” ,其中,所有的數據庫參數是默認的行動是沒有指定數據庫因此可以省略。 The command will run mysqlcheck client to automatically analyze and optimize all databases at 1 am everyday.該命令將運行mysqlcheck客戶端會自動分析和優化所有數據庫在每天凌晨1點。 Note that there is not space between -p and your password for root.請注意,不存在空間之間的p和密碼的根源。 You can change the running time to your preference, and also change the options for mysqlcheck command.您可以更改運行時間為您選擇,同時也改變選擇mysqlcheck命令。 If you just want to check and optimize certain databases or certain tables without the database, use the following syntax:如果你只是要檢查和優化某些數據庫或某些表的數據庫,請使用以下語法:
mysqlcheck [options] db_name [tables] mysqlcheck [選項] db_name [表]
mysqlcheck [options] –databases DB1 [DB2 DB3...] mysqlcheck [選項]數據庫DB1 [的DB2 DB3 ... ]
You may want to remove –auto-repair switch from the above command, as a table repair operation might cause data loss under some circumstances the operation due to causes include but are not limited to filesystem errors.您可能想要移除,汽車修理開關從上述命令,作為一個表修復操作可能導致數據丟失,在某些情況下的運作由於原因包括但不限於文件的錯誤。 For those who has changed the character set and collation of MySQL databases may also need to use –default-character-set option.對於那些誰改變了字符集和整理的MySQL數據庫,可能還需要使用默認字符集的選擇。 More information on all available switches and options available can be found更多的信息所有可用的交換機和可供選擇可以找到 here在這裡 . 。
IMPORTANT : This is a machine translated page which is provided "as is" without warranty. 重要說明:這是一台機器翻譯網頁這是“原樣”提供,無保修。 Machine translation may be difficult to understand.機器翻譯可能很難理解。 Please refer to請參閱 original English article英文原文的文章 whenever possible.只要有可能。
Share and contribute or get technical support and help at共享和貢獻或獲得技術支持和幫助 My Digital Life Forums 我的數字生活論壇 . 。
Related Articles相關文章
- MySQL Database Performance Tuning Best Practices Video Tutorial MySQL數據庫性能調整的最佳做法視頻教程
- Install Web Server in Windows XP with Apache2, PHP5 and MySQL4 - Part 4 Web服務器安裝在Windows XP中使用的Apache2 , PHP5和MySQL4 -第4部分
- Change and Reset MySQL root Password變化和重置MySQL的root密碼
- How to Find and Replace Text in MySQL Database using SQL如何查找和替換文字MySQL數據庫中使用SQL
- WordPress MySQL SQL Query Error in WPDB Class WordPress的MySQL的SQL查詢錯誤WPDB級
- Change or Set MySQL Long Query Time Value for log-slow-queries更改或設置MySQL的長查詢時間價值為日誌慢查詢
- Using PHP-MySQL Persistent Connections to Run WordPress Blog用PHP , MySQL的持久連接運行WordPress的博客
- Enable Logging of Slow Queries (Slow Query Log) in MySQL Database啟用日誌記錄慢查詢(慢速查詢日誌)在MySQL數據庫
- How to Delete Existing WordPress Post Revisions Stored/Saved如何刪除現有的WordPress的修改後儲存/保存
- Remove or Trim First or Last Few Characters in MySQL Database with SQL刪除或修剪第一或過去的幾年中人物MySQL數據庫與SQL

































January 16th, 2008 06:40 08年1月16日06:40
Note that -–auto-repair should have two dashes請注意, -汽車修理應該有兩個破折號
Also, you might want to leave “> /dev/null” out for the first few runs, to see the results of the command (if you put MAILTO=me@mydomain.com at the top of the crontab, the results will get sent there).此外,您可能要離開“ ”的/ dev /空“出的前幾個運行時,看到的結果,命令(如果你把地址= me@mydomain.com上方的crontab ,其結果將得到派往那裡) 。
May 6th, 2008 19:15 2008年五月六日19:15
I did not know that it was nesessary to perform a regular check for mysql.我不知道這是nesessary進行定期檢查的數據庫。
September 20th, 2008 18:34二〇 〇八年9月20日18:34
Sure mysql does need frequent tunning, and also I have seen a lot of the servers running in the default configuration.當然數據庫確實需要經常整,還我看到了很多服務器運行中的默認配置。 which happens to be a very modest one.這恰好是一個非常溫和的。 If you have access to the mysql configuration file, there are some values that can make your server breathe more often.如果您有機會獲得MySQL的配置文件,有一些價值,可以讓你的服務器呼吸更加頻繁。 And make your visitors more happy.使您的訪問者更幸福。