Two Methods for regular execution of MySQL statements

Source: Internet
Author: User
In linux, usrbinmysql-uquot; usernamequot;-pquot; passwordquot; dbname -- executequot; deletefromtable1; select *

In linux,/usr/bin/mysql-uquot; usernamequot;-pquot; passwordquot; dbname -- execute = quot; delete from table1; select *

Requirement: at the end of some activities, you need to query game data at a certain time point in time.

Implementation: Two Methods

One worker uses mysql.exe + at/to schedule tasks

D: \ mysql \ bin \ mysql.exe-u "username"-p "password" dbname -- execute = "delete from table1; select * from table2"> c: \ result.txt

Open the specified data warehouse, execute the begin SQL statement, and redirect the result to the result.txt file of the C drive. You can then use the at command and scheduled task for scheduled execution. Of course, you can add the ftp command to upload the query result file to the specified machine.

Linux

/Usr/bin/mysql-u "username"-p "password" dbname -- execute = "delete from table1; select * from table2">/tmp/result

Feature: You need to enable the scheduled task.

Ii. Use the mysql events Function

Enable this function first

Set global event_scheduler = 1;

The following statement runs the defined SQL statement at a specified time. For more detailed usage, see the mysql help documentation.

Create event test on schedule at timestamp '2017-09-09 09:00:00 'do select * from db1.table1 into outfile 'result.txt ';

Features: the mysql version must be 5.1.6 or later, and may affect the performance to a certain extent.

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.