We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Problems scheduling a batch file to run mysql command on Windows 2008 Server

Medium Priority
2,232 Views
Last Modified: 2012-06-21
Windows 2008 Server Standard SP2 64-bit.

I have a batch file scheduled to run every day that unzips a file and imports the data into a MySQL database on the same server.  The file unzips properly but will not import the data.  The mysql command runs for about 30 seconds and then the task ends like it completed successfully.  No errors in event log or any screen output.  It works fine if I manually execute the batch file, but not from task scheduler.  Here is the command that will not execute properly when scheduled:
mysql -h 192.168.15.7 -u user -ppassword -P4928 database < "d:\folder\file.sql"

The task scheduler log shows event 102 Task Completed op code (2) and event 201 Action Completed return code 0 op code (2).  The task is set to run using a local administrator account and is set to run whether user is logged in or not.

Please help.  Thanks!
Comment
Watch Question

Commented:
To import MySQL on a remote machines, using PSexec, I run the following command line on the remote PC.:

"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe" -u root -pPASSWORD < C:\database.sql

This is assuming that the database.sql is on the remote C:\ drive.

Author

Commented:
Sorry, but that doesn't address my question/issue at all.  I am not importing MySQL on a remote machine - it's the local machine.  And as I stated, the command works fine when executed manually.  This issue is with using task scheduler to execute the command.
Ron MalmsteadInformation Services Manager
CERTIFIED EXPERT

Commented:
Can you post the contents of the bat file please?

Seems strange that manual excution works but a scheduled exec doesn't, for the same file.
Must be  a simple reason it's failing in schtsks
Ron MalmsteadInformation Services Manager
CERTIFIED EXPERT

Commented:
What happens when you change "mysql"... to the full path ? "C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe"

Author

Commented:
Here is the exact batch file.  The task is configured to direct the screen output to a txt file for later review:

@echo --------------------------------------------------------------

@echo Task started @ %date% %time%
@7za e -y "d:\eclinicalworks\ecwbackup.zip" -o"d:\mysqlbackup"
@echo Finished unzip @ %date% %time%

@mysql -h 192.168.15.7 -u user -pPW -P4928 database < "d:\mysqlbackup\ecwbackup.sql"
@echo Finished import @ %date% %time%

I changed mysql to the full path and will let you know the result.

Thanks.

Author

Commented:
No improvement after changing mysql to full path.  Same result.
Ron MalmsteadInformation Services Manager
CERTIFIED EXPERT

Commented:
"" The task is configured to direct the screen output to a txt file for later review"""

....so your task looks something like this...??

c:\batchfile.bat > output.txt

If so,...
You might take that out, and put it in the bat file itself....

@echo Finished import @ %date% %time% > output.txt

Author

Commented:
Ok, so changing the output didn't help.  I even tried taking it out completely.  Interestingly (annoyingly), when I comment out the 7za line, the mysql import works fine.  But when the 7za command executes, it unzips the file but then the mysql command doesn't work.  Again... this only happens when run from scheduled tasks - when the batch file is run manually everything works as expected.  Weird...  Will I have to have two separate scheduled tasks?  One for the unzip and the other for the import?  I guess I will try that next...  
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
?

Author

Commented:
no one came up with a better solution
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.