42-1 mysql备份与恢复

01 mysql备份与恢复

1、mysqldump备份数据库(使用场合:1G以下的数据库)

1)单个数据库

[[email protected] ~]# mysqldump -uroot --databases hellodb > /root/helldb01.sql

2)多个数据库

[[email protected] ~]# mysqldump -uroot --databases hellodb mydb > /root/hellodb_mydb.sql

3)备份全部数据库

[[email protected] ~]# mysqldump -uroot --all-databases --lock-all-tables --master-data=2 > /root/all.sql

2、灾难恢复事例:(本示例有误,需要整理)

原服务器:192.168.1.73

恢复服务器:192.168.1.72

原服务器:执行插入、删除操作;

MariaDB [(none)]> use hellodb;

MariaDB [hellodb]> desc students;

#插入一条记录

MariaDB [hellodb]> insert into students (Name,Age,Gender,ClassID,TeacherID) VALUES (‘Chao Cai‘,47,‘M‘,3,7);

MariaDB [hellodb]> select * from students;

+-------+---------------+-----+--------+---------+-----------+

| StuID | Name          | Age | Gender | ClassID | TeacherID |

+-------+---------------+-----+--------+---------+-----------+

|     1 | Shi Zhongyu   |  22 | M      |       2 |         3 |

|     2 | Shi Potian    |  22 | M      |       1 |         7 |

|     3 | Xie Yanke     |  53 | M      |       2 |        16 |

|     4 | Ding Dian     |  32 | M      |       4 |         4 |

|     5 | Yu Yutong     |  26 | M      |       3 |         1 |

|     6 | Shi Qing      |  46 | M      |       5 |      NULL |

|     7 | Xi Ren        |  19 | F      |       3 |      NULL |

|     8 | Lin Daiyu     |  17 | F      |       7 |      NULL |

|     9 | Ren Yingying  |  20 | F      |       6 |      NULL |

|    10 | Yue Lingshan  |  19 | F      |       3 |      NULL |

|    11 | Yuan Chengzhi |  23 | M      |       6 |      NULL |

|    12 | Wen Qingqing  |  19 | F      |       1 |      NULL |

|    13 | Tian Boguang  |  33 | M      |       2 |      NULL |

|    14 | Lu Wushuang   |  17 | F      |       3 |      NULL |

|    15 | Duan Yu       |  19 | M      |       4 |      NULL |

|    16 | Xu Zhu        |  21 | M      |       1 |      NULL |

|    17 | Lin Chong     |  25 | M      |       4 |      NULL |

|    18 | Hua Rong      |  23 | M      |       7 |      NULL |

|    19 | Xue Baochai   |  18 | F      |       6 |      NULL |

|    20 | Diao Chan     |  19 | F      |       7 |      NULL |

|    21 | Huang Yueying |  22 | F      |       6 |      NULL |

|    22 | Xiao Qiao     |  20 | F      |       1 |      NULL |

|    23 | Ma Chao       |  23 | M      |       4 |      NULL |

|    24 | Xu Xian       |  27 | M      |    NULL |      NULL |

|    25 | Sun Dasheng   | 100 | M      |    NULL |      NULL |

|    26 | Chao Cai      |  47 | M      |       3 |         7 |

+-------+---------------+-----+--------+---------+-----------+

26 rows in set (0.03 sec)

#删除某一条记录

MariaDB [hellodb]> DELETE FROM students WHERE StuID=3;

还原服务器:先使用mysqldump备份文件还原,再使用二进制日志文件还原

[[email protected] ~]# scp all.sql 192.168.1.72:/root

[[email protected] ~]# yum -y install mariadb-server

[[email protected] ~]# systemctl start mariadb.service 

[[email protected] ~]# mysql

MariaDB [(none)]> SHOW DATABASES;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.00 sec)

MariaDB [(none)]> \q

[[email protected] ~]# mysql < all.sql

[[email protected] ~]# mysql

MariaDB [(none)]> SHOW DATABASES;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| hellodb            |

| mydb               |

| mysql              |

| performance_schema |

| test               |

+--------------------+

6 rows in set (0.00 sec)

MariaDB [(none)]> use hellodb;

MariaDB [hellodb]> SELECT * FROM students;

+-------+---------------+-----+--------+---------+-----------+

| StuID | Name          | Age | Gender | ClassID | TeacherID |

+-------+---------------+-----+--------+---------+-----------+

|     1 | Shi Zhongyu   |  22 | M      |       2 |         3 |

|     2 | Shi Potian    |  22 | M      |       1 |         7 |

|     3 | Xie Yanke     |  53 | M      |       2 |        16 |

|     4 | Ding Dian     |  32 | M      |       4 |         4 |

|     5 | Yu Yutong     |  26 | M      |       3 |         1 |

|     6 | Shi Qing      |  46 | M      |       5 |      NULL |

|     7 | Xi Ren        |  19 | F      |       3 |      NULL |

|     8 | Lin Daiyu     |  17 | F      |       7 |      NULL |

|     9 | Ren Yingying  |  20 | F      |       6 |      NULL |

|    10 | Yue Lingshan  |  19 | F      |       3 |      NULL |

|    11 | Yuan Chengzhi |  23 | M      |       6 |      NULL |

|    12 | Wen Qingqing  |  19 | F      |       1 |      NULL |

|    13 | Tian Boguang  |  33 | M      |       2 |      NULL |

|    14 | Lu Wushuang   |  17 | F      |       3 |      NULL |

|    15 | Duan Yu       |  19 | M      |       4 |      NULL |

|    16 | Xu Zhu        |  21 | M      |       1 |      NULL |

|    17 | Lin Chong     |  25 | M      |       4 |      NULL |

|    18 | Hua Rong      |  23 | M      |       7 |      NULL |

|    19 | Xue Baochai   |  18 | F      |       6 |      NULL |

|    20 | Diao Chan     |  19 | F      |       7 |      NULL |

|    21 | Huang Yueying |  22 | F      |       6 |      NULL |

|    22 | Xiao Qiao     |  20 | F      |       1 |      NULL |

|    23 | Ma Chao       |  23 | M      |       4 |      NULL |

|    24 | Xu Xian       |  27 | M      |    NULL |      NULL |

|    25 | Sun Dasheng   | 100 | M      |    NULL |      NULL |

+-------+---------------+-----+--------+---------+-----------+

25 rows in set (0.00 sec)

查看备份文件,查到MASTER_LOG_POS的值,并记下

[[email protected] ~]# less all.sql

-- MySQL dump 10.14  Distrib 5.5.50-MariaDB, for Linux (x86_64)

--

-- Host: localhost    Database: 

-- ------------------------------------------------------

-- Server version       5.5.50-MariaDB

/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */;

/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */;

/*!40101 SET @[email protected]@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8 */;

/*!40103 SET @[email protected]@TIME_ZONE */;

/*!40103 SET TIME_ZONE=‘+00:00‘ */;

/*!40014 SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;

/*!40014 SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;

/*!40101 SET @[email protected]@SQL_MODE, SQL_MODE=‘NO_AUTO_VALUE_ON_ZERO‘ */;

/*!40111 SET @[email protected]@SQL_NOTES, SQL_NOTES=0 */;

--

-- Position to start replication or point-in-time recovery from

--

-- CHANGE MASTER TO MASTER_LOG_FILE=‘mysql-bin.000001‘, MASTER_LOG_POS=245;

--

-- Current Database: `hellodb`

--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `hellodb` /*!40100 DEFAULT CHARACTER SET utf8 */;

USE `hellodb`;

--

这里的值为:MASTER_LOG_POS=245

[[email protected] ~]# mysqlbinlog --start-position=245 /var/lib/mysql/mysql-bin.000001 > incre.sql

[[email protected] ~]# scp incre.sql 192.168.1.72:/root

[[email protected] ~]# mysql < incre.sql

[[email protected] ~]# mysql

MariaDB [(none)]> use hellodb;

MariaDB [hellodb]> SELECT * FROM students;

+-------+---------------+-----+--------+---------+-----------+

| StuID | Name          | Age | Gender | ClassID | TeacherID |

+-------+---------------+-----+--------+---------+-----------+

|     1 | Shi Zhongyu   |  22 | M      |       2 |         3 |

|     2 | Shi Potian    |  22 | M      |       1 |         7 |

|     4 | Ding Dian     |  32 | M      |       4 |         4 |

|     5 | Yu Yutong     |  26 | M      |       3 |         1 |

|     6 | Shi Qing      |  46 | M      |       5 |      NULL |

|     7 | Xi Ren        |  19 | F      |       3 |      NULL |

|     8 | Lin Daiyu     |  17 | F      |       7 |      NULL |

|     9 | Ren Yingying  |  20 | F      |       6 |      NULL |

|    10 | Yue Lingshan  |  19 | F      |       3 |      NULL |

|    11 | Yuan Chengzhi |  23 | M      |       6 |      NULL |

|    12 | Wen Qingqing  |  19 | F      |       1 |      NULL |

|    13 | Tian Boguang  |  33 | M      |       2 |      NULL |

|    14 | Lu Wushuang   |  17 | F      |       3 |      NULL |

|    15 | Duan Yu       |  19 | M      |       4 |      NULL |

|    16 | Xu Zhu        |  21 | M      |       1 |      NULL |

|    17 | Lin Chong     |  25 | M      |       4 |      NULL |

|    18 | Hua Rong      |  23 | M      |       7 |      NULL |

|    19 | Xue Baochai   |  18 | F      |       6 |      NULL |

|    20 | Diao Chan     |  19 | F      |       7 |      NULL |

|    21 | Huang Yueying |  22 | F      |       6 |      NULL |

|    22 | Xiao Qiao     |  20 | F      |       1 |      NULL |

|    23 | Ma Chao       |  23 | M      |       4 |      NULL |

|    24 | Xu Xian       |  27 | M      |    NULL |      NULL |

|    25 | Sun Dasheng   | 100 | M      |    NULL |      NULL |

|    26 | Chao Cai      |  47 | M      |       3 |         7 |

+-------+---------------+-----+--------+---------+-----------+

25 rows in set (0.00 sec)

数据恢复完成

3、 基于lvm2实现热备(本示例待验证)

配置mariadb存储的lvm2分区

[[email protected] ~]# fdisk /dev/sda

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

Command (m for help): n

Partition type:

  p   primary (2 primary, 0 extended, 2 free)

  e   extended

Select (default p): 

Using default response p

Partition number (3,4, default 3): 

First sector (51374080-251658239, default 51374080): 

Using default value 51374080

Last sector, +sectors or +size{K,M,G} (51374080-251658239, default 251658239): +10G

Partition 3 of type Linux and of size 10 GiB is set

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

[[email protected] ~]# partx -a /dev/sda

[[email protected] ~]# pvcreate /dev/sda3

 Physical volume "/dev/sda3" successfully created

[[email protected] ~]# vgcreate myvg /dev/sda3

 Volume group "myvg" successfully created

[[email protected] ~]# lvcreate -L +5G -n mydata myvg

 Logical volume "mydata" created.

[[email protected] ~]# mkfs.xfs /dev/myvg/mydata  

[[email protected] ~]# systemctl stop mariadb.service

[[email protected] ~]# mount /dev/myvg/mydata /data/

[[email protected] ~]# mkdir -p /data/mysql

[[email protected] ~]# chown -R mysql.mysql /data/mysql/

[[email protected] ~]# vim /etc/my.cnf

修改

datadir=/var/lib/mysql

datadir=/data/mysql

[[email protected] ~]# systemctl start mariadb.service

[[email protected] ~]# mysql < all.sql 

[[email protected] ~]# mysql -e ‘SHOW MASTER STATUS‘ > /root/pos.`date +%F`

[[email protected] ~]# cat pos.2016-11-02 

File    Position        Binlog_Do_DB    Binlog_Ignore_DB

mysql-bin.000002        245

#对数据库作lvm2备份

[[email protected] ~]# lvcreate -L 500M -s -n mydata-snap -p r /dev/myvg/mydata

 Logical volume "mydata-snap" created.

#对数据库作修改操作  

MariaDB [(none)]> UNLOCK TABLES;

MariaDB [(none)]> use hellodb;

MariaDB [hellodb]> DELETE FROM students WHERE StuID=5;

MariaDB [hellodb]> DELETE FROM students WHERE StuID=11;

MariaDB [hellodb]> SELECT * FROM students;

+-------+---------------+-----+--------+---------+-----------+

| StuID | Name          | Age | Gender | ClassID | TeacherID |

+-------+---------------+-----+--------+---------+-----------+

|     1 | Shi Zhongyu   |  22 | M      |       2 |         3 |

|     2 | Shi Potian    |  22 | M      |       1 |         7 |

|     3 | Xie Yanke     |  53 | M      |       2 |        16 |

|     4 | Ding Dian     |  32 | M      |       4 |         4 |

|     6 | Shi Qing      |  46 | M      |       5 |      NULL |

|     7 | Xi Ren        |  19 | F      |       3 |      NULL |

|     8 | Lin Daiyu     |  17 | F      |       7 |      NULL |

|     9 | Ren Yingying  |  20 | F      |       6 |      NULL |

|    10 | Yue Lingshan  |  19 | F      |       3 |      NULL |

|    12 | Wen Qingqing  |  19 | F      |       1 |      NULL |

|    13 | Tian Boguang  |  33 | M      |       2 |      NULL |

|    14 | Lu Wushuang   |  17 | F      |       3 |      NULL |

|    15 | Duan Yu       |  19 | M      |       4 |      NULL |

|    16 | Xu Zhu        |  21 | M      |       1 |      NULL |

|    17 | Lin Chong     |  25 | M      |       4 |      NULL |

|    18 | Hua Rong      |  23 | M      |       7 |      NULL |

|    19 | Xue Baochai   |  18 | F      |       6 |      NULL |

|    20 | Diao Chan     |  19 | F      |       7 |      NULL |

|    21 | Huang Yueying |  22 | F      |       6 |      NULL |

|    22 | Xiao Qiao     |  20 | F      |       1 |      NULL |

|    23 | Ma Chao       |  23 | M      |       4 |      NULL |

|    24 | Xu Xian       |  27 | M      |    NULL |      NULL |

|    25 | Sun Dasheng   | 100 | M      |    NULL |      NULL |

+-------+---------------+-----+--------+---------+-----------+

23 rows in set (0.00 sec)

 

[[email protected] ~]# systemctl stop mariadb.service 

[[email protected] ~]# lvremove /dev/myvg/mydata-snap 

[[email protected] ~]# umount /dev/myvg/mydata 

[[email protected] ~]# mke2fs -t ext4 /dev/myvg/mydata 

[[email protected] ~]# mount /dev/myvg/mydata /data/

[[email protected] ~]# mkdir /data/{mysql,binlogs}

[[email protected] ~]# chown -R mysql.mysql /data/*

[[email protected] ~]# vim /etc/my.cnf.d/server.cnf 

在[server]行(9行左右)添加

log_bin=/data/binlogs/mysql-bin

[[email protected] ~]# systemctl start mariadb.service 

MariaDB [(none)]> SET sql_log_bin=0;

MariaDB [(none)]> source /root/all.sql

MariaDB [test]> SHOW DATABASES;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| hellodb            |

| mydb               |

| mysql              |

| performance_schema |

| test               |

+--------------------+

6 rows in set (0.00 sec)

MariaDB [test]> SHOW MASTER STATUS;

+------------------+----------+--------------+------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+------------------+----------+--------------+------------------+

| mysql-bin.000003 |      245 |              |                  |

+------------------+----------+--------------+------------------+

1 row in set (0.00 sec)

MariaDB [(none)]> SET sql_log_bin=1;

MariaDB [test]> FLUSH TABLES WITH READ LOCK;

[[email protected] ~]# mysql -e ‘flush logs;‘

[[email protected] ~]# mysql -e "SHOW MASTER STATUS;"

+------------------+----------+--------------+------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+------------------+----------+--------------+------------------+

| mysql-bin.000004 |      245 |              |                  |

+------------------+----------+--------------+------------------+

[[email protected] ~]# mysql -e "SHOW MASTER STATUS;" > /root/pos-`date +%F`

[[email protected] ~]# cat pos-2016-11-03 

File    Position        Binlog_Do_DB    Binlog_Ignore_DB

mysql-bin.000004        245

[[email protected] ~]# lvcreate -L 2G -n mydata-snap -s -p r /dev/myvg/mydata  Logical volume "mydata-snap" created.

MariaDB [test]> UNLOCK TABLES;

MariaDB [hellodb]> DELETE FROM students WHERE StuID=18;

Query OK, 1 row affected (0.01 sec)

MariaDB [hellodb]> SELECT * FROM students;

+-------+---------------+-----+--------+---------+-----------+

| StuID | Name          | Age | Gender | ClassID | TeacherID |

+-------+---------------+-----+--------+---------+-----------+

|     1 | Shi Zhongyu   |  22 | M      |       2 |         3 |

|     2 | Shi Potian    |  22 | M      |       1 |         7 |

|     3 | Xie Yanke     |  53 | M      |       2 |        16 |

|     4 | Ding Dian     |  32 | M      |       4 |         4 |

|     5 | Yu Yutong     |  26 | M      |       3 |         1 |

|     6 | Shi Qing      |  46 | M      |       5 |      NULL |

|     8 | Lin Daiyu     |  17 | F      |       7 |      NULL |

|     9 | Ren Yingying  |  20 | F      |       6 |      NULL |

|    10 | Yue Lingshan  |  19 | F      |       3 |      NULL |

|    11 | Yuan Chengzhi |  23 | M      |       6 |      NULL |

|    12 | Wen Qingqing  |  19 | F      |       1 |      NULL |

|    13 | Tian Boguang  |  33 | M      |       2 |      NULL |

|    14 | Lu Wushuang   |  17 | F      |       3 |      NULL |

|    15 | Duan Yu       |  19 | M      |       4 |      NULL |

|    16 | Xu Zhu        |  21 | M      |       1 |      NULL |

|    17 | Lin Chong     |  25 | M      |       4 |      NULL |

|    19 | Xue Baochai   |  18 | F      |       6 |      NULL |

|    20 | Diao Chan     |  19 | F      |       7 |      NULL |

|    21 | Huang Yueying |  22 | F      |       6 |      NULL |

|    22 | Xiao Qiao     |  20 | F      |       1 |      NULL |

|    23 | Ma Chao       |  23 | M      |       4 |      NULL |

|    24 | Xu Xian       |  27 | M      |    NULL |      NULL |

|    25 | Sun Dasheng   | 100 | M      |    NULL |      NULL |

+-------+---------------+-----+--------+---------+-----------+

23 rows in set (0.01 sec)

[[email protected] ~]# mount -r /dev/myvg/mydata-snap /mnt

[[email protected] ~]# ls /mnt/

binlogs  lost+found  mysql

[[email protected] ~]# cd /mnt/

[[email protected] mnt]# ls mysql/

aria_log.00000001  hellodb  ib_logfile0  mydb   performance_schema

aria_log_control   ibdata1  ib_logfile1  mysql  test

[[email protected] mnt]# ls binlogs/

mysql-bin.000001  mysql-bin.000003  mysql-bin.index

mysql-bin.000002  mysql-bin.000004

[[email protected] mnt]# cp -a mysql/ /tmp/

[[email protected] mnt]# cp -a /data/binlogs/ /tmp/

[[email protected] mnt]# systemctl stop mariadb.service 

#模拟误删除数据库中数据

[[email protected] mnt]# rm -rf /data/mysql/*

[[email protected] mnt]# rm -rf /data/binlogs/*

#恢复

[[email protected] mnt]# cp -a /tmp/mysql/* /data/mysql/

[[email protected] mnt]# cp -a /tmp/binlogs/* /data/binlogs/

[[email protected] mnt]# systemctl start mariadb.service 

[[email protected] mnt]# mysql

MariaDB [(none)]> SHOW BINARY LOGS;

+------------------+-----------+

| Log_name         | File_size |

+------------------+-----------+

| mysql-bin.000001 |     30334 |

| mysql-bin.000002 |   1038814 |

| mysql-bin.000003 |       288 |

| mysql-bin.000004 |       245 |

| mysql-bin.000005 |       245 |

+------------------+-----------+

MariaDB [(none)]> use hellodb;

MariaDB [hellodb]> SELECT * FROM students;

+-------+---------------+-----+--------+---------+-----------+

| StuID | Name          | Age | Gender | ClassID | TeacherID |

+-------+---------------+-----+--------+---------+-----------+

|     1 | Shi Zhongyu   |  22 | M      |       2 |         3 |

|     2 | Shi Potian    |  22 | M      |       1 |         7 |

|     3 | Xie Yanke     |  53 | M      |       2 |        16 |

|     4 | Ding Dian     |  32 | M      |       4 |         4 |

|     5 | Yu Yutong     |  26 | M      |       3 |         1 |

|     6 | Shi Qing      |  46 | M      |       5 |      NULL |

|     7 | Xi Ren        |  19 | F      |       3 |      NULL |

|     8 | Lin Daiyu     |  17 | F      |       7 |      NULL |

|     9 | Ren Yingying  |  20 | F      |       6 |      NULL |

|    10 | Yue Lingshan  |  19 | F      |       3 |      NULL |

|    11 | Yuan Chengzhi |  23 | M      |       6 |      NULL |

|    12 | Wen Qingqing  |  19 | F      |       1 |      NULL |

|    13 | Tian Boguang  |  33 | M      |       2 |      NULL |

|    14 | Lu Wushuang   |  17 | F      |       3 |      NULL |

|    15 | Duan Yu       |  19 | M      |       4 |      NULL |

|    16 | Xu Zhu        |  21 | M      |       1 |      NULL |

|    17 | Lin Chong     |  25 | M      |       4 |      NULL |

|    18 | Hua Rong      |  23 | M      |       7 |      NULL |

|    19 | Xue Baochai   |  18 | F      |       6 |      NULL |

|    20 | Diao Chan     |  19 | F      |       7 |      NULL |

|    21 | Huang Yueying |  22 | F      |       6 |      NULL |

|    22 | Xiao Qiao     |  20 | F      |       1 |      NULL |

|    23 | Ma Chao       |  23 | M      |       4 |      NULL |

|    24 | Xu Xian       |  27 | M      |    NULL |      NULL |

|    25 | Sun Dasheng   | 100 | M      |    NULL |      NULL |

+-------+---------------+-----+--------+---------+-----------+

25 rows in set (0.00 sec)

#数据恢复到备份时的数据;

MariaDB [hellodb]> \q

Bye

[[email protected] ~]# cat pos-2016-11-03 

File    Position        Binlog_Do_DB    Binlog_Ignore_DB

mysql-bin.000004        245

[[email protected] ~]# cd /tmp/

[[email protected] ~]# cd /tmp/binlogs/

[[email protected] binlogs]# ls

mysql-bin.000001  mysql-bin.000003  mysql-bin.index

mysql-bin.000002  mysql-bin.000004

[[email protected] binlogs]# mysqlbinlog --start-position=245 mysql-bin.000004 /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;

/*!40019 SET @@session.max_insert_delayed_threads=0*/;

/*!50003 SET @[email protected]@COMPLETION_TYPE,COMPLETION_TYPE=0*/;

DELIMITER /*!*/;

# at 4

#161103 13:08:44 server id 1  end_log_pos 245   Start: binlog v 4, server v 5.5.50-MariaDB created 161103 13:08:44

# Warning: this binlog is either in use or was not closed properly.

BINLOG ‘

XMYaWA8BAAAA8QAAAPUAAAABAAQANS41LjUwLU1hcmlhREIAbG9nAAAAAAAAAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAA2QAEGggAAAAICAgCAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

AAAAAAAAAAAA9VR4dg==

‘/*!*/;

DELIMITER ;

# End of log file

ROLLBACK /* added by mysqlbinlog */;

/*!50003 SET [email protected]_COMPLETION_TYPE*/;

/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

时间: 2024-09-28 11:43:47

42-1 mysql备份与恢复的相关文章

MySQL备份与恢复

body { font-family: Helvetica, arial, sans-serif; font-size: 14px; line-height: 1.6; padding-top: 10px; padding-bottom: 10px; background-color: white; padding: 30px } body>*:first-child { margin-top: 0 !important } body>*:last-child { margin-bottom:

42-2 mysql备份与恢复

02 mysql备份与恢复 实战:percona-xtrabackup备份还原数据库 原服务器:source 192.168.1.133 CentOS7.2  备份服务器:restore 192.168.1.132 CentOS7.2 1.使用indobackupex进行完全备份 [[email protected] ~]# yum install percona-xtrabackup-2.3.2-1.el7.x86_64.rpm [[email protected] ~]# rpm -ql p

mysql常用操作 mysql备份与恢复

先登录mysql  ==>mysql -uroot -p 查看数据库的版本 select version(); 查看有哪些库 show datases; 查看当前处于哪个库 select database(); 查看当前登录用户 select user(); 查看某个库下面的表: use db; show tables; 查看表的字段: desc dong; 创建库 create database db1; 创建表 create  table  tb1 (`id` int(4),`name`ch

MySQL备份与恢复常用方法总结(mysqldump/xtrabackup/lvm快照备份/二进制日志及时点恢复)

MySQL备份与恢复常用方法总结 (mysqldump/xtrabackup/lvm快照备份/逻辑备份与恢复/二进制日志及时点恢复) 自言:学习在于总结,把所了解的类似东西放到一起更能加深记忆 一.了解备份相关知识 1)按服务器备份时状态可分为:     热备份:读.写不受影响:     温备份:仅可以执行读操作:     冷备份:离线备份:读.写操作均中止:2)按服务器备份数据集可分为:     物理备份:复制数据文件:     逻辑备份:将数据导出至文本文件中:3)按服务器备份数据量可分为:

ch5 MySQL 备份与恢复

第 5 章 MySQL 备份与恢复 前言 数据库的备份与恢复一直都是 DBA 工作中最为重要的部分之一,也是基本工作之一.任何正式环境的数据库都必须有完整的备份计划和恢复测试,本章内容将主要介绍 MySQL 数据库的备份与恢复相关内容. 5.1 数据库备份使用场景 你真的明白了自己所做的数据库备份是要面对什么样的场景的吗? 我想任何一位维护过数据库的人都知道数据库是需要备份的,也知道备份数据库是数据库维护必不可少的一件事情.那么是否每一个人都知道自己所做的备份到底是为了应对哪些场景的呢?抑或者说

MySQL 备份与恢复 常用命令

1.3.MySQL 备份与恢复 1.MySQL 备份 # mysqldump -uroot -pqweasd -S /data/3307/mysql.sock db8 > /backup/3307-db8.sql # mysqldump -uroot -pqweasd -S /data/3307/mysql.sock db8 > /backup/3307-db8_$(date +%F).sql # mysqldump -uroot -pqweasd -S /data/3307/mysql.so

MySQL备份与恢复-mydumper

上一片博文中,我们说明了mysqldump的备份与恢复.因为mysqldump是单线程导出,单线程恢复的,因此备份与恢复的时间比较长! 首先来安装mydumper: 下载源码:https://github.com/maxbube/mydumper 安装: 1解压 unzip mydumper-master 2:安装依赖包 yum install glib2-devel mysql-devel zlib-devel pcre-devel zlib gcc-c++ gcc cmake -y 3:编译

MySQL用户管理、sql常用语句、mysql备份与恢复

MySQL用户管理 创建用户 grant all on *.* to 'user1'@'localhost' identified by '123456'; grant all on db1.* to 'user2'@'%' identified by '123456'; //创建user2用户,所有ip都能登录,指定权限为db1库下的所有表: flush privileges; 刷新授权 .:表示所有库和表:user1:用户名:localhost:登录ip,默认localhost为本机登录ip

mysql备份与恢复-xtracebackup

因为percona打算放弃使用innobackupex备份工具,因此我们这里也说明一下innobackupex的兄弟工具xtraceback工具的使用 这个工具的安装可以参考上面的一些博文,上面详细说明了innobackupex的备份与使用:https://www.cnblogs.com/wxzhe/p/10033983.html 首先我们来看一下xtracbackup的帮助文档: [[email protected] ~]# xtrabackup --help xtrabackup: reco