您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“mysql中mysqldumper怎么用”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“mysql中mysqldumper怎么用”這篇文章吧。
并行處理:
使用mydumper命令的局限在與他是一個單線程進程。但開源的mydumper是一個很好的替代。
mydumper(http://www.mysqldumper.org/)是一個在GNU GPLv3許可下發布的高性能MySQL備份和恢復工具集。mydumper是多線程的,他創建一個mysql備份就比隨mysql發布的mysqldump工具要快得多。mydumper也有從源端服務器恢復二進制日志的能力。
mydumper的優點:
多線程,可以是轉存數據快很多。
mydumper的輸出已于管理和分析,因為他的表和元數據是分開的單獨文件。
所有線程都維護有一直的快照,這邊提供了精準的主從位置。
Mydumper支持Perl正則表達式,這樣就既可以包括是數據庫名和報名的模式匹配,也可以配置這種匹配。
通過名為myloader的多線程工具,mydumper工具集也可以從mydumper備份中恢復數據。
mydumper必須在源代碼上進行編輯。這就需要帶有C++編輯器的系統。另外還需要如下組件:
Cmake、帶有開發包的Glib2、帶有開發包的PCRE、mysql的客戶端庫和開發工具。
安裝步驟如下:
依賴包:Fedora, RedHat and CentOS: yum install glib2-devel* mysql-devel* zlib-devel* pcre-devel* openssl-devel* -y
tar -zxvf mydumper-0.2.3.tar.gz
cd mydumper-0.2.0.3/
cmake .
make
./mydumper -help
sudo cp mydumper /usr/local/bin
簡單用法:
mkdir /mysql/bakcup/mydumper
cd /mysql/backup/mydumper
time mydumper
[root@d4jtarmsvurd01 mydumper_bak]# pwd
/mysql/mydumper_bak
[root@d4jtarmsvurd01 mydumper_bak]# ls ex*
metadata mysql.proc-schema.sql
mysql-schema-create.sql mysql.procs_priv-schema.sql
mysql.columns_priv-schema.sql mysql.servers-schema.sql
mysql.db-schema.sql mysql.tables_priv-schema.sql
mysql.db.sql mysql.time_zone-schema.sql
mysql.event-schema.sql mysql.time_zone_leap_second-schema.sql
mysql.func-schema.sql mysql.time_zone_name-schema.sql
mysql.help_category-schema.sql mysql.time_zone_transition-schema.sql
mysql.help_category.sql mysql.time_zone_transition_type-schema.sql
....................
當在冗長模式中運行時,會產生額外的輸出,單所提供的信息中并不包括完整的輸出目錄:
[root@d4jtarmsvurd01 mydumper_bak]# mydumper -v 3
** Message: Connected to a MySQL server
** Message: Started dump at: 2016-07-05 15:16:56
** Message: Written master status
** Message: Thread 1 connected using MySQL connection ID 1367
** Message: Thread 2 connected using MySQL connection ID 1368
** Message: Thread 3 connected using MySQL connection ID 1369
** Message: Thread 4 connected using MySQL connection ID 1370
** Message: Thread 2 dumping data for `mysql`.`db`
** Message: Thread 1 dumping data for `mysql`.`columns_priv`
** Message: Thread 3 dumping data for `mysql`.`event`
** Message: Empty table mysql.event
** Message: Empty table mysql.columns_priv
** Message: Thread 2 dumping data for `mysql`.`func`
** Message: Thread 1 dumping data for `mysql`.`help_category`
** Message: Thread 3 dumping data for `mysql`.`help_keyword`
** Message: Thread 1 dumping data for `mysql`.`help_relation`
** Message: Empty table mysql.func
** Message: Thread 2 dumping data for `mysql`.`help_topic`
** Message: Thread 3 dumping data for `mysql`.`host`
** Message: Thread 1 dumping data for `mysql`.`ndb_binlog_index`
** Message: Empty table mysql.ndb_binlog_index
** Message: Thread 1 dumping data for `mysql`.`plugin`
** Message: Empty table mysql.plugin
** Message: Thread 1 dumping data for `mysql`.`proc`
** Message: Empty table mysql.proc
** Message: Thread 1 dumping data for `mysql`.`procs_priv`
** Message: Empty table mysql.host
** Message: Thread 3 dumping data for `mysql`.`servers`
** Message: Empty table mysql.servers
** Message: Thread 3 dumping data for `mysql`.`tables_priv`
** Message: Empty table mysql.procs_priv
** Message: Thread 1 dumping data for `mysql`.`time_zone`
** Message: Empty table mysql.time_zone
** Message: Thread 1 dumping data for `mysql`.`time_zone_leap_second`
** Message: Empty table mysql.time_zone_leap_second
** Message: Thread 1 dumping data for `mysql`.`time_zone_name`
** Message: Empty table mysql.time_zone_name
** Message: Thread 1 dumping data for `mysql`.`time_zone_transition`
** Message: Empty table mysql.tables_priv
** Message: Thread 3 dumping data for `mysql`.`time_zone_transition_type`
** Message: Empty table mysql.time_zone_transition
** Message: Thread 1 dumping data for `mysql`.`user`
** Message: Thread 1 dumping data for `sanxing`.`sanxing`
** Message: Empty table mysql.time_zone_transition_type
** Message: Thread 3 dumping data for `test`.`guijian`
** Message: Thread 3 dumping schema for `mysql`.`columns_priv`
** Message: Thread 1 dumping schema for `mysql`.`db`
** Message: Thread 1 dumping schema for `mysql`.`event`
** Message: Thread 1 dumping schema for `mysql`.`func`
** Message: Thread 1 dumping schema for `mysql`.`help_category`
** Message: Thread 1 dumping schema for `mysql`.`help_keyword`
** Message: Thread 3 dumping schema for `mysql`.`help_relation`
** Message: Thread 1 dumping schema for `mysql`.`help_topic`
** Message: Thread 3 dumping schema for `mysql`.`host`
** Message: Thread 1 dumping schema for `mysql`.`ndb_binlog_index`
** Message: Thread 1 dumping schema for `mysql`.`plugin`
** Message: Thread 3 dumping schema for `mysql`.`proc`
** Message: Thread 1 dumping schema for `mysql`.`procs_priv`
** Message: Thread 1 dumping schema for `mysql`.`servers`
** Message: Thread 1 dumping schema for `mysql`.`tables_priv`
** Message: Thread 3 dumping schema for `mysql`.`time_zone`
** Message: Thread 1 dumping schema for `mysql`.`time_zone_leap_second`
** Message: Thread 3 dumping schema for `mysql`.`time_zone_name`
** Message: Thread 1 dumping schema for `mysql`.`time_zone_transition`
** Message: Thread 3 dumping schema for `mysql`.`time_zone_transition_type`
** Message: Thread 3 dumping schema for `mysql`.`user`
** Message: Thread 3 dumping schema for `sanxing`.`sanxing`
** Message: Thread 3 dumping schema for `test`.`guijian`
** Message: Non-InnoDB dump complete, unlocking tables
** Message: Thread 3 shutting down
** Message: Thread 1 shutting down
** Message: Thread 4 shutting down
** Message: Thread 2 shutting down
** Message: Finished dump at: 2016-07-05 15:16:56
[root@d4jtarmsvurd01 mydumper_bak]# ls
export-20160705-151255 export-20160705-151656
[root@d4jtarmsvurd01 mydumper_bak]#
用法:
[root@d4jtarmsvurd01 mydumper_bak]# mydumper --help
Usage:
mydumper [OPTION...] multi-threaded MySQL dumping
Help Options:
-?, --help Show help options
Application Options:
-B, --database Database to dump
-T, --tables-list Comma delimited table list to dump (does not exclude regex option)
-o, --outputdir Directory to output files to
-s, --statement-size Attempted size of INSERT statement in bytes, default 1000000
-r, --rows Try to split tables into chunks of this many rows. This option turns off --chunk-filesize
-F, --chunk-filesize Split tables into chunks of this output file size. This value is in MB
-c, --compress Compress output files
-e, --build-empty-files Build dump files even if no data available from table
-x, --regex Regular expression for 'db.table' matching
-i, --ignore-engines Comma delimited list of storage engines to ignore
-m, --no-schemas Do not dump table schemas with the data
-d, --no-data Do not dump table data
-G, --triggers Dump triggers
-E, --events Dump events
-R, --routines Dump stored procedures and functions
-k, --no-locks Do not execute the temporary shared read lock. WARNING: This will cause inconsistent backups
--less-locking Minimize locking time on InnoDB tables.
-l, --long-query-guard Set long query timer in seconds, default 60
-K, --kill-long-queries Kill long running queries (instead of aborting)
-D, --daemon Enable daemon mode
-I, --snapshot-interval Interval between each dump snapshot (in minutes), requires --daemon, default 60
-L, --logfile Log file name to use, by default stdout is used
--tz-utc SET TIME_ZONE='+00:00' at top of dump to allow dumping of TIMESTAMP data when a server has data in different time zones or data is being moved between servers with different time zones, defaults to on use --skip-tz-utc to disable.
--skip-tz-utc
--use-savepoints Use savepoints to reduce metadata locking issues, needs SUPER privilege
--success-on-1146 Not increment error count and Warning instead of Critical in case of table doesn't exist
--lock-all-tables Use LOCK TABLE for all, instead of FTWRL
-U, --updated-since Use Update_time to dump only tables updated in the last U days
--trx-consistency-only Transactional consistency only
-h, --host The host to connect to
-u, --user Username with privileges to run the dump
-p, --password User password
-P, --port TCP/IP port to connect to
-S, --socket UNIX domain socket file to use for connection
-t, --threads Number of threads to use, default 4
-C, --compress-protocol Use compression on the MySQL connection
-V, --version Show the program version and exit
-v, --verbose Verbosity of output, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2
[root@d4jtarmsvurd01 mydumper_bak]#
通過正則表達式選項排除mysql和測試的模式對象:
mydumper --user root --regex '^(?!(mysql|test))'
壓縮:默認情況下,所有處處文件都是不壓縮的。但是通過使用-c選項,所有文件都可以被壓縮。
[root@d4jtarmsvurd01 mydumper_bak]# mydumper -c
[root@d4jtarmsvurd01 mydumper_bak]# ls -lrt
total 12
drwx------ 2 root root 4096 Jul 5 15:12 export-20160705-151255
drwx------ 2 root root 4096 Jul 5 15:16 export-20160705-151656
drwx------ 2 root root 4096 Jul 5 15:20 export-20160705-152048
[root@d4jtarmsvurd01 mydumper_bak]# cd export-20160705-152048/
[root@d4jtarmsvurd01 export-20160705-152048]# ls
metadata mysql.proc-schema.sql.gz
mysql-schema-create.sql.gz mysql.procs_priv-schema.sql.gz
mysql.columns_priv-schema.sql.gz mysql.servers-schema.sql.gz
mysql.db-schema.sql.gz mysql.tables_priv-schema.sql.gz
mysql.db.sql.gz mysql.time_zone-schema.sql.gz
mysql.event-schema.sql.gz mysql.time_zone_leap_second-schema.sql.gz
................
mydumper生產多個與元數據、表數據、表模式和二進制日志相關的文件。
.metadata文件中保存著轉存的開始和結束時間以及主二進制日志的位置。當執行轉存時,一個.metadata文件邊被創建到輸出目錄中:
備份目錄中的素有文件:
[root@d4jtarmsvurd01 export-20160705-151656]# ls
metadata mysql.proc-schema.sql
mysql-schema-create.sql mysql.procs_priv-schema.sql
mysql.columns_priv-schema.sql mysql.servers-schema.sql
mysql.db-schema.sql mysql.tables_priv-schema.sql
mysql.db.sql mysql.time_zone-schema.sql
mysql.event-schema.sql mysql.time_zone_leap_second-schema.sql
mysql.func-schema.sql mysql.time_zone_name-schema.sql
mysql.help_category-schema.sql mysql.time_zone_transition-schema.sql
mysql.help_category.sql mysql.time_zone_transition_type-schema.sql
mysql.help_keyword-schema.sql mysql.user-schema.sql
mysql.help_keyword.sql mysql.user.sql
mysql.help_relation-schema.sql sanxing-schema-create.sql
mysql.help_relation.sql sanxing.sanxing-schema.sql
mysql.help_topic-schema.sql sanxing.sanxing.sql
mysql.help_topic.sql test-schema-create.sql
mysql.host-schema.sql test.guijian-schema.sql
mysql.ndb_binlog_index-schema.sql test.guijian.sql
mysql.plugin-schema.sql
[root@d4jtarmsvurd01 export-20160705-151656]# more metadata
Started dump at: 2016-07-05 15:16:56
SHOW MASTER STATUS:
Log: mysql-bin.000002
Pos: 106
GTID:(null)
Finished dump at: 2016-07-05 15:16:56
[root@d4jtarmsvurd01 export-20160705-151656]# pwd
/mysql/mydumper_bak/export-20160705-151656
[root@d4jtarmsvurd01 export-20160705-151656]#
在使用mydumper的時候可以通過show processlist來監控線程。
可以使用兩種不同的方式存儲表數據:將所有表數據村委一個文件或者將一個表的數據塊存為多個文件,如果未指定--row選項,則將為每個表創建一個文件,命令規則類似于database.table.sql。
關于mydumper生成文件的類型如下:
db_name.table_name-schema_name.sql ---表結構文件
db_name.table_name.sql ---表數據文件
db_name-schema-create.sql ---數據庫創建腳本
mydumper的還原工具為:myloader,使用說明如下:
[root@d4jtarmsvurd01 mydumper_bak]# myloader --help
Usage:
myloader [OPTION...] multi-threaded MySQL loader
Help Options:
-?, --help Show help options
Application Options:
-d, --directory Directory of the dump to import
-q, --queries-per-transaction Number of queries per transaction, default 1000
-o, --overwrite-tables Drop tables if they already exist
-B, --database An alternative database to restore into
-s, --source-db Database to restore
-e, --enable-binlog Enable binary logging of the restore data
-h, --host The host to connect to
-u, --user Username with privileges to run the dump
-p, --password User password
-P, --port TCP/IP port to connect to
-S, --socket UNIX domain socket file to use for connection
-t, --threads Number of threads to use, default 4
-C, --compress-protocol Use compression on the MySQL connection
-V, --version Show the program version and exit
-v, --verbose Verbosity of output, 0 = silent, 1 = errors, 2 = warnings, 3 = info, default 2
恢復測試:
1、備份數據庫:
[root@d4jtarmsvurd01 mydumper_bak]# mydumper -u root -p root123 -v 3
2、刪除其中的某一個數據庫:
mysql> drop database sanxing;
Query OK, 2 rows affected (0.06 sec)
3、開始恢復其中的一個數據庫:
[root@d4jtarmsvurd01 mydumper_bak]# myloader -d /mysql/mydumper_bak/export-20170224-151158 -o -B sanxing -u root -p 'root123'
4、檢查恢復情況:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| guijian |
| mysql |
| sanxing |
| test |
+--------------------+
5 rows in set (0.00 sec)
注意原本有兩個表的數據庫,在恢復時指定了所有數據庫備份的目錄,此時所有的數據庫表都被恢復到了,刪除的庫,(故此,在恢復的時候注意要使用單個數據庫的備份,即什么樣的備份能恢復什么樣的數據庫)
mysql> use sanxing;
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_sanxing |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| guijian |
| guijian01 |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| jiehun |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| sanxing |
| servers |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
25 rows in set (0.00 sec)
mysql>
單獨測試恢復:
mysql> use guijian;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+-------------------+
| Tables_in_guijian |
+-------------------+
| test |
| test01 |
+-------------------+
2 rows in set (0.00 sec)
mysql> exit
Bye
[root@d4jtarmsvurd01 mydumper_bak]# mydumper -u root -p root123 -B guijian -v 3
** Message: Connected to a MySQL server
** Message: Started dump at: 2017-02-24 15:28:18
** Message: Written master status
** Message: Thread 1 connected using MySQL connection ID 2807
** Message: Thread 2 connected using MySQL connection ID 2808
** Message: Thread 3 connected using MySQL connection ID 2809
** Message: Thread 4 connected using MySQL connection ID 2810
** Message: Thread 1 dumping data for `guijian`.`test`
** Message: Thread 3 dumping schema for `guijian`.`test`
** Message: Thread 2 dumping data for `guijian`.`test01`
** Message: Thread 4 dumping schema for `guijian`.`test01`
** Message: Non-InnoDB dump complete, unlocking tables
** Message: Thread 4 shutting down
** Message: Thread 1 shutting down
** Message: Thread 3 shutting down
** Message: Thread 2 shutting down
** Message: Finished dump at: 2017-02-24 15:28:18
[root@d4jtarmsvurd01 mydumper_bak]# ls -lrt
總用量 4
drwx------ 2 root root 4096 2月 24 15:28 export-20170224-152818
[root@d4jtarmsvurd01 mydumper_bak]# cd export-20170224-152818/
[root@d4jtarmsvurd01 export-20170224-152818]# ls -lrt
總用量 24
-rw-r--r-- 1 root root 68 2月 24 15:28 guijian-schema-create.sql
-rw-r--r-- 1 root root 1110 2月 24 15:28 guijian.test.sql
-rw-r--r-- 1 root root 2817 2月 24 15:28 guijian.test-schema.sql
-rw-r--r-- 1 root root 1112 2月 24 15:28 guijian.test01.sql
-rw-r--r-- 1 root root 2819 2月 24 15:28 guijian.test01-schema.sql
-rw-r--r-- 1 root root 143 2月 24 15:28 metadata
[root@d4jtarmsvurd01 export-20170224-152818]#
mysql> drop database guijian;
Query OK, 2 rows affected (0.01 sec)
mysql> exit
[root@d4jtarmsvurd01 mydumper_bak]# myloader -d /mysql/mydumper_bak/export-20170224-152818 -o -B guijian -u root -p 'root123'
[root@d4jtarmsvurd01 mydumper_bak]#
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show tables;
ERROR 1046 (3D000): No database selected
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| guijian |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> use guijian;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+-------------------+
| Tables_in_guijian |
+-------------------+
| test |
| test01 |
+-------------------+
2 rows in set (0.00 sec)
以上是“mysql中mysqldumper怎么用”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。