Skip to content
Advertisement

How do I fix the error that occurs when I enter the file path and date in mysqldump?

How do I fix the error that occurs when I enter the file path and date in mysqldump?

I ran the mysqldump command as follows in cmd:

set _my_datetime=%date:-=%

mysqldump -u root -p --all-databases -pMyPassword > C:Program FilesMariaDB 10.4databackup%_my_datetime%.sql

But the result is:

I wonder how to modify the above command in Windows server environment.

Advertisement

Answer

Because the %date:-=% will be evaluated as Tue 10/19/2021, and this date separator forward slash / conflicts with the path being used in the mysqldump command.

which is an incorrect Windows path syntax and throws a generic syntax exception in your case.

Solution
Find a way to format the date with separator as dash - or underscore _ instead.

You can simply use

will give a filename pattern: mysql_backup_10-19-2021-10_08_12.sql

Date format in Windows command line can be taunting in its way.

Reference:
how to add date and time with backupfile name using mysqldump from command prompt and to define the path of backupfile
Format date and time in a Windows batch script

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement