备份数据库
mysqldump -u root -p database_name > /your-path/mysql_name_back.sql
还原数据库
source /your-path/back.sql
- linux脚本备份
- 新建脚本mysqlback.sh
db_user="root"
db_passwd="root"
db_name="your_database_name"
# the directory for story your backup file.you shall change this dir
backup_dir="/var/backups"
# date format for backup file (dd-mm-yyyy)
time="$(date +"%Y_%m_%d_%H:%M:%S")"
mysqldump -h 127.0.0.1 -u$db_user -p$db_passwd $db_name --ignore-table=$db_name.your_table > "$backup_dir/$db_name"_"$time.sql"
$db_name.your_table 为需要忽略备份的表名称,例如一些大的日志表