zoukankan      html  css  js  c++  java
  • mysql备份与还原

    #!/bin/bash

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

    # 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"

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

    # 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/"

    backups_user="root"

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

    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
    done

    # 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

  • 相关阅读:
    Avoiding the Backup of Online Redo Logs
    RMAN-20201: datafile not found in the recovery catalog
    ORA-15081: failed to submit an I/O operation to a disk
    字符串替换数字问题
    jstl换行符处理
    字符串匹配问题
    careercup题目20131013
    careercup题目20131010
    careercup题目201330928
    面试题(一)
  • 原文地址:https://www.cnblogs.com/xianguang/p/8927226.html
Copyright © 2011-2022 走看看