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.创建一个新的作业,登录到服务器,以root的身份或任何其他用户,然后编辑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或其他的CRON目录。 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 - aao -自动修复中美根- P的[密码] > /开发/空
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 2008年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).此外,您可能会想要离开“ > /开发/无效” ,首次阐明了几个运行时,看到的结果,命令(如果你把的mailto = me@mydomain.com在上方的crontab ,结果将得到派有工作) 。
May 6th, 2008 19:15 2008年5月6日19时15分
I did not know that it was nesessary to perform a regular check for mysql.我不知道,这是nesessary执行定期检查,同时为MySQL开发。