myloader恢複mysql資料庫樣本,myloadermysql樣本

來源:互聯網
上載者:User

myloader恢複mysql資料庫樣本,myloadermysql樣本

    mydumper是針對mysqlDatabase Backup的一個輕量級第三方的開源工具,備份方式為邏輯備份。它支援多線程,備份速度遠高於原生態的mysqldump以及眾多優異特性。與其相配套的恢複工具則是myloader,主要用於將dump出來的sql以並行的方式進行恢複。本文主要描述myloader的使用方法並給出樣本。

    有關mydumper的相關參考
        mydumper備份mysql資料庫樣本  
        mydumper安裝及安裝故障匯總  
 
1、單庫的備份與恢複
[root@app ~]# mydumper -u leshami -p xxx -B sakila -o /tmp/bak
[root@app ~]# mysql -urobin -pxxx   -e "show databases"|grep restoredb
[root@app ~]# mysql -urobin -pxxx   \
>  -e "create table sakila.tb like sakila.actor;             ###建立測試表
>      insert into sakila.tb select * from sakila.actor"

###將備份庫恢複到一個新資料庫,如restoredb
[root@app ~]# myloader  -u leshami -p xxx  -B restoredb -d /tmp/bak
[root@app ~]# mysql -urobin -pxxx   -e "show databases"|grep restoredb
restoredb

###恢複到原庫
[root@app ~]# myloader  -u leshami -p xxx   -B sakila -d /tmp/bak
** (myloader:3642): CRITICAL **: Error restoring sakila.category from file sakila.category-schema.sql: Table 'category' already exists

---增加-o參數進行覆蓋恢複
[root@app ~]# myloader  -u leshami -p xxx   -o -B sakila -d /tmp/bak


2、單表恢複
[root@app ~]# mysql -urobin -pxxx   -e "drop table sakila.tb"
[root@app ~]# mysql -urobin -pxxx   -e "select count(*) from sakila.tb"
Warning: Using a password on the command line interface can be insecure.
ERROR 1146 (42S02) at line 1: Table 'sakila.tb' doesn't exist

###直接調用備份的schema以及資料檔案執行即可
[root@app ~]# mysql -urobin -pxxx   \
>  -e "use sakila;
>      source /tmp/bak/sakila.tb-schema.sql
>      source /tmp/bak/sakila.tb.sql"

###驗證結果
[root@app ~]# mysql -urobin -pxxx   -e "select count(*) from sakila.tb"
Warning: Using a password on the command line interface can be insecure.
+----------+
| count(*) |
+----------+
|      200 |
+----------+


3、執行個體層級的備份與恢複
[root@app ~]# rm -rf /tmp/bak/*
[root@app ~]# mydumper -u leshami -p xxx   --regex '^(?!(mysql|test))' -o /tmp/bak

###嘗試刪除部分資料庫
[root@app ~]# mysql -urobin -pxxx   \
>  -e "drop database tempdb;drop database sakila"

###基於全部備份檔案進行恢複
[root@app ~]# myloader  -u leshami -p xxx   -o -d /tmp/bak


4、擷取協助
[root@app ~]# 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
                   還原期間每個事務insert的數目,預設是1k
  -o, --overwrite-tables            Drop tables if they already exist(表存在即覆蓋)
  -B, --database                    An alternative database to restore into
  -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

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.