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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch File

Status
Not open for further replies.

buzzt

Programmer
Oct 17, 2002
171
CA
I am trying to create a batch file to run MySQL commands under Windows 2K Server. I have read the info on "Using mysql in Batch Mode" on the MySQL site, but still can't get it to run a file like TEST.TXT containing "USE DB_NAME". Ultimately, I want to automate the batch file to run MySQL commands like "DELETE FROM TABLE_NAME" on certain dates.

Has anyone done this before?
 
It's not hard.

I have a table named "counties" in the database "bar".

I create a text file "test.txt" which reads:

use foo;
select * from counties;

I then invoke the mysql command-line application:

/path/to/mysql/bin/mysql -u <my username> -p < test.txt

The app asks me for my password, then returns the data to the command-line.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
But how would this work in an automated batch file? The batch will open the /path/to/mysql/bin/mysql, but ignore the rest. You would then have to manually run the test.txt.
 
perhaps make an .bat first ??

you can also look foor unconventional automation at

I use this to run programs or open files and then send keystrokes. everything can be compiled to an executable.
 
ia sutomated batch file somthing new aor a kind of scripting feature in win 2003



[ponder]
----------------
ur feedback is a very welcome desire
 
If you can create a .bat file you just put as many mysql calls in it as you care to:

/mysql/bin/mysql.exe -vvv -u username -ppassword <sqlcommandstorun.sql >logs/output.log

mysql.exe calls mysql
-vvv asks for verbose output
-u is username
-p asks for a password and to avoid it prompting for the password you can place the password after the -p with no gap - but then don't forget to protect the file from prying eyes
< pipes in the commands from a pre-prepared text file
> pipes the verbose output to a file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top