7

I have WampServer 2.0 that is installed on Windows on my laptop.

I'm running on it an application that I wrote. The application is working with MySQL database.

I would like to make backups of this database periodically.

How this can be done ?

How could I define cron on Windows ?

Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
  • Possible duplicate of [PHP regular backup of mysql data](http://stackoverflow.com/questions/38916163/php-regular-backup-of-mysql-data) – e4c5 Aug 15 '16 at 00:47
  • Hi, you can simply backup your MySQL Server databases automatically with the help of MySQLBackupFTP, check it https://mysqlbackupftp.com – Alexandr Omelchenko Apr 30 '18 at 12:28

3 Answers3

12

The rough equivalent of crontab -e for Windows is the at command, as in:

at 22:00 /every:M,T,W,Th,F C:\path\to\mysql\bin\mysqldump.exe ...

Running the at command by itself lists the tasks you've created using at.

The mysqldump documentation is here.

RichieHindle
  • 272,464
  • 47
  • 358
  • 399
  • I agree with Ruel. 'at' is a very neat app I never knew existed! Got a +1 from me too. It would be an even better answer if you gave a full example rather than the '...'. After I figure it out I'll update your answer. ;) – Arvo Bowen Mar 29 '14 at 02:33
  • FYI, while trying to running 'at' on Windows with cygwin, it told me that it was deprecated and to use schtasks.exe instead – George Jul 21 '14 at 14:11
8

The most popular way to backup MySQL database is to use mysqldump:

  1. Open a Windows command line.

  2. Specify the directory to mysqldump utility

    cd "C:\Program Files\MySQL\MySQL Server 5.7\bin"

  3. Create a dump of your MySQL database.

mysqldump.exe --user=YourUserName --password=YourPassword --host=localhost --port=3306 --result-file="Pathdump.sql" --databases "DatabaseName"

Also, there are a lot of third-party tools, which can perform MySQL backups automatically on a regular basis.

Community
  • 1
  • 1
0

You could use a bash script.

#!/bin/sh
mysqldump -uroot -ppwd --opt db1 > /sqldata/db1.sql
mysqldump -uroot -ppwd --opt db2 > /sqldata/db2.sql

cd /sqldata/
tar -zcvf sqldata.tgz *.sql
cd /scripts/
perl emailsql.pl

http://paulbradley.tv/38/

Michael Eakins
  • 4,149
  • 3
  • 35
  • 54