• 【转载】mysql 热备份


    原文: http://www.jb51.net/article/70967.htm

      热备和冷备是两个相对的概念,冷备是把数据库服务,比如MySQL,Oracle停下来,然后使用拷贝、打包或者压缩命令对数据目录进行备份;那么我们很容易想到热备就是在MySQL或者其他数据库服务在运行的情况下进行备份。但是,这里存在一个问题,因为生产库在运行的情况下,有对该库的读写,读写频率有可能高,也可能低,不管频率高低,总会就会造成备份出来的数据和生产库中的数据不一致的情况。热备这段时间,其他人不可以操作是不现实的,因为你总不可能终止用户访问Web程序。要解决这个问题,可以采用指定备份策略,比如哪个时间段进行备份,备份哪些数据等等,总之,保证数据的完整性和一致性,切记,备份重于一切!!!
           热备可以对多个库进行备份,可以对单张表或者某几张表进行备份。但是无法同时备份多个库多个表,只有分开备份。下面我们看下热备的示意图,并进行热备模拟。

                

    热备模拟

    1、对单个库进行备份
    第一步,移除LVM快照。(如果没有创建,忽略此步)

    [root@serv01 data]# lvremove /dev/data/smydata 
    Do you really want to remove active logical volume smydata? [y/n]: y
     Logical volume "smydata" successfully removed
    

     第二步,设置MySQL的密码

    mysql> set password=password("123456");
    Query OK, 0 rows affected (0.00 sec)
    

     第三步,查看MySQL是否启动。因为是热备,所以要求MySQL服务启动

    [root@serv01 data]# /etc/init.d/mysqld status
     SUCCESS! MySQL running (2664)
    

     第四步,导出单个数据库

    [root@serv01 data]# cd /databackup/
    #本质是导出为SQL
    [root@serv01 databackup]# mysqldump -uroot -p123456 --database larrydb
    

     第五步,模拟数据丢失,进入MySQL,删除数据库

    root@serv01 data]# mysql -uroot -p123456
    

     第六步,导入数据

     [root@serv01 databackup]# mysql -u root -p 123456 <larrydb.sql
    

    第七步,登录MySQL,查看数据是否正常

    [root@serv01 data]# mysql -uroot -p123456
    Welcome to the MySQL monitor. Commands end with ; or g.
    Your MySQL connection id is 6
    Server version: 5.5.29-log Source distribution
     
    Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
     
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
     
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
     
    mysql> show database;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1
    mysql> show databases;
    +--------------------+
    | Database  |
    +--------------------+
    | information_schema |
    | crm  |
    | game  |
    | hello  |
    | larrydb  |
    | mnt  |
    | mysql  |
    | performance_schema |
    | test  |
    +--------------------+
    9 rows in set (0.00 sec)
     
    mysql> use larrydb;
    Database changed
    mysql> select * from class;
    +------+--------+
    | cid | cname |
    +------+--------+
    | 1 | linux |
    | 2 | oracle |
    +------+--------+
    2 rows in set (0.00 sec)
     
    mysql> select * from stu;
    +------+---------+------+
    | sid | sname | cid |
    +------+---------+------+
    | 1 | larry01 | 1 |
    | 2 | larry02 | 2 |
    +------+---------+------+
    2 rows in set (0.00 sec)
    

     对多个库进行备份
    第一步,查看有哪些数据库

    mysql> show databases;
    

     第二步,备份多个库

    [root@serv01 databackup]# mysqldump -uroot -p123456 --databases larrydb game > larrydb_game.sql
    [root@serv01 databackup]# ll larrydb_game.sql 
    

     备份所有的库

    [root@serv01 databackup]# mysqldump -uroot -p123456 --all-databases > all_databases.sql
    [root@serv01 databackup]# ll all_databases.sql -h
    
  • 相关阅读:
    css关于margin计算top/bottom/left/right值,总是不居中的相关说明。
    微信小程序开发工具,设置默认首页的方式。
    html Video标签关于自动播放(autoplay)和支持播放的编码格式相关的文档
    [Vue v3]vueclasscomponent @Component 装饰器和 Vue 基类的更改
    git项目,执行命令this operation must be run in a work tree
    220708Allegro等长操作
    AGC008E Next or Nextnext
    AGC023E Inversions
    AOP之环绕通知 proceedingjoinpoint和前置后置通知 joinpoint区别
    maven中的groupId和artifactId到底指的是什么? groupid公司组织名称 artifactId 项目名称
  • 原文地址:https://www.cnblogs.com/yingsong/p/9002526.html
Copyright © 2020-2023  润新知