Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Database backup automatically on a windows server

Is there a way to back up MySQL database automatically at certain times of the day for designated servers or send an email with an attachment.. Which ever do you think is the best and safest way to achieve this?

like image 880
Coderwannabe Avatar asked Feb 02 '13 21:02

Coderwannabe


People also ask

How do I set up an automatic backup in SQL?

In Task Scheduler, right-click on Task Schedule Library and click on Create Basic task…. Enter the name for the new task (for example: SQLBackup) and click Next. Select Daily for the Task Trigger and click Next. Set the recurrence to one day and click Next.


3 Answers

Best way to do this would be

mysqldump.exe --user=YourUserName --password=YourPassword --host=localhost --port=3306 --result-file="Path\dump.sql" --databases "DatabaseName1" "Database2"


mysqldump.exe --user=root --password=root  --host=localhost --port=3306 --result-file="c:\www\db\backup.%date:~10,4%%date:~7,2%%date:~4,2%.sql" --default-character-set=utf8 --single-transaction=TRUE --databases "dbtest1" "dbtest2"

The pattern backup.%date:~10,4%%date:~7,2%%date:~4,2%.sql will create a unique name (backup20131010.sql) each time it will run

Now you just need to call this command in your task scheduler. That's it. :)

like image 198
Tarun Gupta Avatar answered Oct 11 '22 09:10

Tarun Gupta


I would use Windows Task Scehduler/cron (depending on your system) and mysqldump. Scroll down in the link, it includes some insights how to achieve what you want.

like image 44
martin Avatar answered Oct 11 '22 10:10

martin


You can add one of these commands to Windows task scheduler:

mysqldump –-user [username] –-password=[password] [database name] > [dump file]

or in a compact way:

mysqldump –u[username] –p[password] [database name] > [dump file]

or:

mysqldump -u[user] -p[password] --result-file="c:\<path>\backup.%DATE:~0,3%.sql" [database]
like image 34
Jess Stone Avatar answered Oct 11 '22 09:10

Jess Stone