简体   繁体   中英

How to do automatic MySQL database Backup?

How to do automatic MySQL Database backup? Is it possible? Can anyone help?

I have a database name 'contacts'.
How can create an automatic backup for it?

Guessing that you are using an unix-like OS. You need to do two steps

Backup your current database

First you need to know how to use mysqldump. This should be a good start point.

mysqldump --all-databases --single-transaction --quick --lock-tables=false > full-backup-$(date +%F).sql -u root -p

Cron your mysqldump

You need to create a file with your credentials. Something like this

sudo nano /home/example_user/.mylogin.cnf

[client]
user = root
password = MySQL root user's password

chmod 600 /home/example_user/.mylogin.cnf

Then, you have to add this line to your cron

sudo nano crontab -e
0 1 * * * /usr/bin/mysqldump --defaults-extra-file=/home/example_user/.my.cnf -u root --single-transaction --quick --lock-tables=false --all-databases > full-backup-$(date +\%F).sql

And that's all.

Source: https://www.linode.com/docs/databases/mysql/use-mysqldump-to-back-up-mysql-or-mariadb/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM