Use mysqldump + crond for backup
Create a database backup sh file such as/root/sbin/db-backup.sh
DATE = 'date + % Y-% m-% d'
/Usr/bin/mysqldump-uroot-p123456 mydatabase>/root/backup/mysql-backup. SQL. $ DATE
Contents are all tables in the backup database mydatabase to the mysql-backup. SQL. $ DATE file, where $ DATE is the DATE dynamically obtained based on the command execution time
Use
/Usr/bin/mysqldump-uroot-p123456 -- all-databases>/root/backup/mysql-backup. SQL. $ DATE
If the database table contains binary fields such as blod, you must add the hex-blod parameter, as shown in
/Usr/bin/mysqldump-uroot-pqaywsx123 -- hex-blod -- all-databases>/root/dbbak/winsmedia. SQL. $ DATE
Add to crond
Edit/etc/crontab
Last line add 30 23 * root/sbin/db-backup.sh
Indicates that the BACKUP command is executed at every day.
Restart and load the crond service crond reload
Note: The contents of the backup mysql-backup. SQL. $ DATE file are encoded as utf8, so make sure that the database encoding is also utf8 otherwise Chinese garbled characters may occur.
You can also add a -- default-charset parameter. For more information, see the help description of the mysqldump command.