Scheduled MySQL action-execute scripts regularly with Cron in Linux

Source: Internet
Author: User
Some want to run database operations at a specified time. If these operations are performed on the WEB Front-end, server resources will be wasted, because the WEB page needs to be refreshed continuously and then determined.

Some want to run database operations at a specified time. If these operations are performed on the WEB Front-end, server resources will be wasted, because the WEB page needs to be refreshed continuously and then determined.

Some want to run database operations at a specified time. If these operations are performed on the WEB Front-end, server resources will be wasted ,, because the web page needs to be refreshed constantly and then determined to execute the operation...

I used this method.

1. Create a directory crond. my in/etc

2. edit/etc/crontab

Minute hour day month week root run-parts/etc/cron. my

3. Create delete_table_msg.sh in cron. my.

The content is as follows:
/Usr/local/MySQL/bin/MySQL-hlocalhost-uroot-pwowangle </etc/cron.12/job. SQL

Why is the absolute path of MySQL required above? Because my MySQL is compiled by myself, and this MySQL command does not exist in the crontab PATH.
Please take a look at the PATH of the/etc/crontab file!
Sometimes, if the scheduled script is not run, check whether your command is in the path!

The job. SQL is the SQL statement to be executed.

! (Digress)
You need to know more about SQL! To complete more tasks! So SQL is very important! This is especially true for WEB developers. I don't believe what kind of excellent WEB programmers can use DW, if you just want a simple select * from table statement like this, you and I should have a hard time waking up!

My A. SQL contains the following content:

use xfcz;
delete from t;

Let's look at these two simple statements, because the data in the T table must be cleared at a fixed time every day.
Let's use your imagination. The most important thing is in this SQL ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.