May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Realize MySQL database automatic backup under Linux

1.Linux under MySQL to create a user backup role, and granted the role of SELECT, RELOAD, SHOW DATABASES, LOCK TABLES and other permissions.

 

mysql> create user 'backuper'@'localhost' identified by '********';
Query OK, 0 rows affected (0.00 sec)

mysql> grant SELECT, RELOAD, SHOW DATABASES, LOCK TABLES on *.* to backuper@localhost;
Query OK, 0 rows affected (0.00 sec)

2. In the system to find a relatively large hard disk to create a backup directory, and create a shell script

vim backup_mohan_db.sh

#!/bin/bash
mysqldump -ubackuper -p******** qianyu_veeker_db > /home/mysql/backup/mohan_db_$(date +%Y%m%d_%H%M%S)

3. To add the scheduled task, you need to install the crontab 
vixie-cron package is the main program for cron; the 
crontabs package is the program used to install, uninstall, or list the tables used to drive the cron daemon.

[root@~]# yum -y install vixie-cron
[root@~]# yum -y install crontabs

4. Set boot to start

[root@ ~]# chkconfig --level 345 crond on

[root@linuxidc etc]# vim crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
#|  .------------- hour (0 - 23)
#|  |  .---------- day of month (1 - 31)
#|  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
#|  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
#|  |  |  |  |
#*  *  *  *  * user-name command to be executed
0 0 * * * /home/mysql/backup/mohan_db.sh

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>