mysqlwindowswindows-7

0x2 error in task scheduler windows 7 mysql


I'm trying to do mysql batabase dump periodically through task scheduler. When I run the following query from command prompt, it gives me the dump. But, when I'm running through Task Scheduler, it's not working.

Query

C:\xampp\mysql\bin\mysqldump.exe --user=root --password=root --host=localhost --database  gm > E:\backupgmdb\gm_backup_%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.sql

Task Scheduler error - 0x2 error screenshot enter image description here

Task Action Definition Screen Print enter image description here


Solution

  • make .bat file, let say c:\xampp\mysql\bin\backup.bat and execute it from scheduller. put into .bat file this commands:

    c:
    cd \
    cd C:\xampp\mysql\bin\
    C:\xampp\mysql\bin\mysqldump.exe --user=root --password=root --host=localhost --database  gm > E:\backupgmdb\gm_backup_%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.sql
    

    Plus, read this: https://serverfault.com/questions/734035/running-a-batch-file-from-task-scheduler-without-user-being-logged-in

    The Task Scheduler in Windows Server 2008 R2 and later and Windows Vista and later executes tasks under a "least privileges" security context by default.

    Open the properties of the task and check Run with highest privileges. Press OK, then enter the password for the administrative account when prompted. This will override the default "least privileges" behavior and will allow the task to run with administrative privileges.