Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to automatically run mysql sql command daily 1

Status
Not open for further replies.

romh

Programmer
Jan 3, 2003
297
US
Hi,
I was wondering if somebody could point me in the right direcion as to how to run sql commands daily at a certain time. Maybe using Windows Scheduler. I could create a .bat file, that opens the mysql database (username and password) and then runs another text file with the sql commands.

I need to run some delete command daily in order to clean up a table with records older than today's date.

Thanks
 
sorry, I mean thanks alot for the help, but I'm using Windows 2000 server. How would I go about doing that?

 
You simply create a batch file which consists of:

\path\to\mysql.exe --user=<yourusername> --password=<yourpassword> <databasename> < mysql_command_file.sql

(for more information on other parameters the mysql.exe command-line application will accept, perform "\path\to\mysql.exe --help")

where mysql_command_file.sql will consist of the SQL commands MySQL will run.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
great. That's what I needed. I'm just not good with bat files.
One more thing, considering that triggers are non-existant, but soon to be released, is my idea of running some delete commands to remove old records with task scheduler, the best way to do it?

I'm writing the front end with asp.net.

Thanks
 
As I understand your question, mysql_command_file.sql (the file containing SQL commands from my post above) will simply contain DELETE queries.

The MySQL command file can have multiple SQL queries in one file if each query is terminated by a semicolon.


I don't understand the significance of your programming the frontend with ASP.Net.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I agree. The asp.net is of no signifance. I just added that for a more detailed question.
I just need something to run those SQL delete commands daily. With triggers, this could be done more easily if you have a table that gets updated daily. I'm not sure though, if you can schedule triggers to run daily.
I've always worked with Mysql, and can;t wait for triggers and store procedures to come out. Been using the 5.0 version, but I can;t call stored procedure with odbc yet. Or can I?



 
Your mechanism shouldn't invoke the trigger daily. Your mechanism, whatever it is, should invoke whatever action the trigger would perform daily. In this case, a periodic deletion of certain records in certain tables.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top