Link to home
Start Free TrialLog in
Avatar of ITLighthouse
ITLighthouse

asked on

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

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!
Avatar of ReneGe
ReneGe
Flag of Canada image

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.
Avatar of ITLighthouse
ITLighthouse

ASKER

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.
Avatar of Ron Malmstead
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
What happens when you change "mysql"... to the full path ? "C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe"
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.
No improvement after changing mysql to full path.  Same result.
"" 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

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...  
ASKER CERTIFIED SOLUTION
Avatar of ITLighthouse
ITLighthouse

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
?
no one came up with a better solution