mydumper的安装与使用

mydumper的安装与使用
下载地址
https://launchpad.net/mydumper/+download


- -安装包

[root@test ~]# rpm -qa | grep cmake
cmake-2.8.12.2-4.el6.x86_64
[root@test ~]# rpm -qa | grep glib2-devel
[root@test ~]# rpm -qa | grep mysql-devel    
[root@test ~]# rpm -qa | grep zlib-devel
[root@test ~]# rpm -qa | grep pcre-devel
[root@test ~]# rpm -qa | grep openssl-devel
[root@test ~]#

-- 安装mydumper

[root@test mysql]# cd mydumper-0.6.2
[root@test mydumper-0.6.2]# ls
binlog.c  cmake           common.h     docs             g_unix_signal.h  mydumper.h  myloader.h  server_detect.c
binlog.h  CMakeLists.txt  config.h.in  g_unix_signal.c  mydumper.c       myloader.c  README      server_detect.h
[root@test mydumper-0.6.2]# cmake .
-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Using mysql-config: /usr/bin/mysql_config
-- Found MySQL: /usr/include/mysql, /usr/lib64/mysql/libmysqlclient_r.so;/usr/lib64/libz.so;/usr/lib64/libpthread.                                           so;/usr/lib64/libcrypt.so;/usr/lib64/libnsl.so;/usr/lib64/libm.so;/usr/lib64/libpthread.so;/usr/lib64/libssl.so;/u                                           sr/lib64/libcrypto.so
-- Found ZLIB: /usr/lib64/libz.so (found version "1.2.3")
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.23")
-- checking for one of the modules 'glib-2.0'
-- checking for one of the modules 'gthread-2.0'
-- checking for module 'libpcre'
--   found libpcre, version 7.8
-- Found PCRE: /usr/include

CMake Warning at docs/CMakeLists.txt:9 (message):
  Unable to find Sphinx documentation generator


-- ------------------------------------------------
-- MYSQL_CONFIG = /usr/bin/mysql_config
-- CMAKE_INSTALL_PREFIX = /usr/local
-- BUILD_DOCS = ON
-- WITH_BINLOG = OFF
-- RUN_CPPCHECK = OFF
-- Change a values with: cmake -D=
-- ------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mysql/mydumper-0.6.2
[root@test mydumper-0.6.2]# make
Scanning dependencies of target mydumper
[ 25%] Building C object CMakeFiles/mydumper.dir/mydumper.c.o
[ 50%] Building C object CMakeFiles/mydumper.dir/server_detect.c.o
[ 75%] Building C object CMakeFiles/mydumper.dir/g_unix_signal.c.o
Linking C executable mydumper
[ 75%] Built target mydumper
Scanning dependencies of target myloader
[100%] Building C object CMakeFiles/myloader.dir/myloader.c.o
Linking C executable myloader
[100%] Built target myloader
[root@test mydumper-0.6.2]# make install
[ 75%] Built target mydumper
[100%] Built target myloader
Install the project...
-- Install configuration: ""
-- Installing: /usr/local/bin/mydumper
-- Removed runtime path from "/usr/local/bin/mydumper"
-- Installing: /usr/local/bin/myloader
-- Removed runtime path from "/usr/local/bin/myloader"
[root@test mydumper-0.6.2]#

-- 全库备份,注意-u -p 后面要有空格,-o 后面跟的是目录,不是文件名

--mydumper -uroot -pmysql -P3306 -o /mysql/backup_all_20181114.sql
[root@test Packages]# mydumper -u root -p mysql -P 3306 --socket=/tmp/mysql3306.sock -o /mysql/backup
[root@test Packages]#

-- 备份的结果如下:

[mysql@test backup]$ ls
metadata                             mysql.innodb_table_stats.sql                mysql.user-schema.sql            test_db.tb_emp7-schema.sql
mysql.columns_priv-schema.sql        mysql.ndb_binlog_index-schema.sql           mysql.user.sql                   test_db.tb_emp8-schema.sql
mysql.db-schema.sql                  mysql.plugin-schema.sql                     tes.animals-schema.sql           test_db.tb_emp8.sql
mysql.db.sql                         mysql.proc-schema.sql                       tes.animals.sql                  test.imptest-schema.sql
mysql.event-schema.sql               mysql.procs_priv-schema.sql                 tes.t1-schema.sql                test.imptest.sql
mysql.func-schema.sql                mysql.proxies_priv-schema.sql               tes.t1.sql                       test.member-schema.sql
mysql.help_category-schema.sql       mysql.proxies_priv.sql                      test.animals-schema.sql          test.member.sql
mysql.help_category.sql              mysql.servers-schema.sql                    test.animals.sql                 test.person-schema.sql
mysql.help_keyword-schema.sql        mysql.slave_master_info-schema.sql          test_db.tb_dept1-schema.sql      test.person.sql
mysql.help_keyword.sql               mysql.slave_relay_log_info-schema.sql       test_db.tb_dept2-schema.sql      test.pet-schema.sql
mysql.help_relation-schema.sql       mysql.slave_worker_info-schema.sql          test_db.tb_deptment3-schema.sql  test.pet.sql
mysql.help_relation.sql              mysql.tables_priv-schema.sql                test_db.tb_emp1-schema.sql       test.shirt-schema.sql
mysql.help_topic-schema.sql          mysql.time_zone_leap_second-schema.sql      test_db.tb_emp2-schema.sql       test.shirt.sql
mysql.help_topic.sql                 mysql.time_zone_name-schema.sql             test_db.tb_emp3-schema.sql       test.shop-schema.sql
mysql.innodb_index_stats-schema.sql  mysql.time_zone-schema.sql                  test_db.tb_emp4-schema.sql       test.shop.sql
mysql.innodb_index_stats.sql         mysql.time_zone_transition-schema.sql       test_db.tb_emp5-schema.sql       test.t1-schema.sql
mysql.innodb_table_stats-schema.sql  mysql.time_zone_transition_type-schema.sql  test_db.tb_emp6-schema.sql       test.t1.sql
[mysql@test backup]$

-- 该目录下有一个metadata文件,该文件记录着当前的binlog和position,方便后续搭建slave库

[mysql@test backup]$ cat metadata
Started dump at: 2018-11-14 09:14:22
SHOW MASTER STATUS:
        Log: mysql3306-bin.000009
        Pos: 32749

Finished dump at: 2018-11-14 09:14:23
[mysql@test backup]$

-- drop掉库test

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| tes                |
| test               |
| test_db            |
| zoo                |
+--------------------+
7 rows in set (0.00 sec)

mysql>
mysql> drop database test;
Query OK, 8 rows affected (0.34 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| tes                |
| test_db            |
| zoo                |
+--------------------+
6 rows in set (0.00 sec)

mysql>

-- 进行恢复test 库

myloader -u root -p mysql -P 3306 --socket=/tmp/mysql3306.sock -B test -d /mysql/backup

[root@test ~]# myloader -u root -p mysql -P 3306 --socket=/tmp/mysql3306.sock -B test -d /mysql/backup

** (myloader:3572): CRITICAL **: Error restoring test.t1 from file tes.t1-schema.sql: Table 't1' already exists

** (myloader:3572): CRITICAL **: Error restoring test.animals from file test.animals-schema.sql: Table 'animals' already exist                               s

** (myloader:3572): CRITICAL **: Error restoring test.t1 from file tes.t1.sql: Column count doesn't match value count at row 1

** (myloader:3572): CRITICAL **: Error restoring test.animals from file test.animals.sql: Column count doesn't match value cou                               nt at row 1

-- 一个比较奇怪的问题,在主库上drop,恢复后,备库没响应 ,不产生binlog吗?,需要加上-e
-- 备份tes 库上的t2 表

mydumper -u root -p mysql -P 3006 --socket=/tmp/mysql3306.sock -B tes -T t2 -o /mysql/backup/

-- 删除掉tes库上的t2表,主从上都没有t2表了  
-- 还原tes库上的t2表 ,这样发现,其他库的表都导入到t2表中,

myloader -u root -p mysql -P 3306 --socket=/tmp/mysql3306.sock -B tes -o t2 -e -d /mysql/backup/ 

-- 把除过t2表的备份从文件夹中删除,再次导入,

myloader -u root -p mysql -P 3306 --socket=/tmp/mysql3306.sock -B tes -o t2 -e -d /mysql/backup2/

-- 还必须要用原来的备份的目录,原因是因为metadata这个文件,要有这个文件

[root@test backup]# myloader -u root -p mysql -P 3306 --socket=/tmp/mysql3306.sock -B tes -o t2 -e -d /mysql/backup2/

** (myloader:8607): CRITICAL **: the specified directory is not a mydumper backup

[root@test backup]#

[root@test backup]# myloader -u root -p mysql -P 3306 --socket=/tmp/mysql3306.sock -B tes -o t2 -e -d /mysql/backup/
[root@test backup]#

-- 结论:
使用myloader恢复某一个表的时候,备份的文件夹里面只有这个表的sql就行了,如果有其他表的sql,其他表的备份会被恢复到指定的表里面。
感觉myloader恢复的时候,不能指定某一个文件进行恢复,是指定某一个文件夹进行恢复。所以文件夹里面只能有要恢复的表 。
另外,恢复的文件夹里面必须要有metadata这个文件,否则没法恢复,会提示这个文件夹不是dumper文件夹。
如果在主库上进行恢复,需要同步在备库,则需要加上-e参数,产生binlog日志 。

end

你可能感兴趣的:(MySQL)