mysql備份與還原

#!/bin/bashmysql

# databases=( '__DATABASE_1__' '__DATABASE_2__' )
databases=('otrs' 'wxi')sql

# The host name of the MySQL database server; usually 'localhost'
db_host="localhost"數據庫

# The port number of the MySQL database server; usually '3306'
db_port="3306"bash

# The MySQL user to use when performing the database backup.
db_user="root"app

# The password for the above MySQL user.
db_pass="winit2015"日誌

# Directory to which backup files will be written. Should end with slash ("/").
backups_dir="/opt/dbbackup/"orm

backups_user="root"server

# Date/time included in the file names of the database backup files.
datetime=$(date +'%Y-%m-%d-%H:%M:%S')ip

for db_name in ${databases[@]}; do
# Create database backup and compress using gzip.
mysqldump --add-drop-table -u $db_user -h $db_host -P $db_port --password=$db_pass $db_name | gzip -9 > $backups_dir$db_name-$datetime.sql.gz
doneit

# Set appropriate file permissions/owner.
# chown $backups_user:$backups_user $backups_dir*--$datetime.sql.gz
# chmod 0400 $backups_dir*--$datetime.sql.gz

 

還原MySQL數據庫的命令

mysql -hhostname -uusername -ppassword databasename < backupfile.sql

還原壓縮的MySQL數據庫

zcat  backupfile.sql.gz | mysql -uusername -ppassword databasename

查看binlog日誌

查看binlog日誌可用用命令 mysqlbinlog  binlog日誌名稱|more

相關文章
相關標籤/搜索