Guidance:I believe many people have used mysqldump, which is easy to store, but slow. FastestBackupThe method is to copy the data directory directly. However, in general, closeMySQLThe service can be done, or when you copy, there will be people reading and writing tables, it will be too much trouble. UseMysqlhotcopyThe above problems will not exist. He can perform hot backup. His backup is very fast. Next I will introduce you to this useful MySQL database backup method.
Mysqlhotcopy is a Perl script originally written and provided by Tim Bunce. It uses lock tables, flush tables, and cp or scp to quickly back up databases. It is the fastest way to back up a database or a single table, but it can only run on the machine where the database directory is located. Mysqlhotcopy is only used to back up MyISAM. It runs in Unix and NetWare
For usage instructions, see the following script. Add it to crotab.
Reference content is as follows:
#! /Bin/sh
# Name: mysqlbackup. sh
# PS: MySQL DataBase Backup, Use mysqlhotcopy script.
# Last Modify: 2008-06-12
# Define variables. Modify the variables as needed
# Define the directory where the script is located
ScriptsDir = 'pwd'
# Database Data Directory
DataDir =/var/lib/mysql
# Data Backup Directory
TmpBackupDir =/tmp/mysqlblackup
BackupDir =/backup/mysql
# Username and password used to back up the database
MysqlUser = root
MysqlPWD = 'you password'
# If the temporary Backup directory exists, clear it. If it does not exist, create it.
If [[-e $ tmpBackupDir]; then
Rm-rf $ tmpBackupDir /*
Else
Mkdir $ tmpBackupDir
Fi
# Create a backup directory if it does not exist
If [[! -E $ backupDir]; then
Mkdir $ backupDir
Fi
# Obtain the database backup list, where you can filter databases that do not want to be backed up
For databases in 'Find $ dataDir-type d | \
Sed-e "s/\/var \/lib \/mysql \ //" | \
Sed-e "s/test //" '; do
If [[$ databases = ""]; then
Continue
Else
# Backing up a database
/Usr/bin/mysqlhotcopy -- user = $ mysqlUser -- password = $ mysqlPWD-q "$ databases" $ tmpBackupDir
DateTime = 'date "+ % Y. % m. % d % H: % M: % S "'
Echo "$ dateTime Database: $ databases backup success! "> MySQLBackup. log
Fi
Done