1. 程式人生 > >my21_mydumper與myloader使用

my21_mydumper與myloader使用

唯一約束 date part rom .sql name 約束 tor mysq

-o 參數

如果不使用-o參數,遇到第一個有主鍵或者唯一約束的數據,則退出當前線程;如果有-o參數,則刪除原來的表,創建新表,再插入數據,主鍵不會發生變化。

** Message: Dropping table or view (if exists) `maell`.`bootrap`
** Message: Creating table `maell`.`bootrap`

mysql -uautomng -prootroot -h127.0.0.1
mkdir -p /data/tmp/table
mydumper -u automng -p rootroot -h 127.0.0.1 -P 3306 -B vodb -T test -e -o /data/tmp/table

mysql> select * from test;
+------+--------+---------+------------------------+---------------------+
| tid | tname | test_id | tvalue | CreateTime |
+------+--------+---------+------------------------+---------------------+
| 2 | aaabbb | 3 | 有張有馳有分寸2 | 2018-11-17 21:39:58 |

| 3 | aaabbb | 4 | 有張有馳有分寸3 | 2018-11-17 21:39:58 |
| 4 | aaabbb | 5 | 有張有馳有分寸4 | 2018-11-17 21:39:58 |
+------+--------+---------+------------------------+---------------------+
3 rows in set (0.00 sec)

刪除、更新、插入各一條記錄
mysql> delete from test where tid=2;
Query OK, 1 row affected (0.06 sec)

mysql> insert into test (tid,tname) values (1,‘123‘);
Query OK, 1 row affected (0.09 sec)

mysql> update test set tid=4 where tvalue=‘wa ka ka‘;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0

mysql> select * from test;
+------+--------+---------+------------------------+---------------------+
| tid | tname | test_id | tvalue | CreateTime |
+------+--------+---------+------------------------+---------------------+
| 3 | aaabbb | 4 | 有張有馳有分寸3 | 2018-11-17 21:39:58 |
| 4 | aaabbb | 5 | 有張有馳有分寸4 | 2018-11-17 21:39:58 |
| 1 | 123 | 7 | NULL | 2019-01-09 18:55:19 |
+------+--------+---------+------------------------+---------------------+
3 rows in set (0.00 sec)


導入,沒有-o參數,默認開啟四線程,表存在時重新插入數據,在遇到第一條重復數據時報錯並退出當前線程;原有庫數據不會發生變化
myloader -u automng -p rootroot -h 127.0.0.1 -P 3306 -B vodb -d /data/tmp/table -v 3

# myloader -u automng -p rootroot -h 127.0.0.1 -P 3306 -B vodb -d /data/tmp/table -v 3
** Message: 4 threads created
** Message: Creating table `vodb`.`test`

** (myloader:23544): CRITICAL **: Error restoring vodb.test from file vodb.test-schema.sql: Table ‘test‘ already exists
** Message: Thread 1 restoring `vodb`.`test` part 0
** Message: Thread 2 shutting down
** Message: Thread 3 shutting down
** Message: Thread 4 shutting down

** (myloader:23544): CRITICAL **: Error restoring vodb.test from file vodb.test.sql: Duplicate entry ‘4‘ for key ‘PRIMARY‘
** Message: Thread 1 shutting down


-o則是將原來數據清除,然後再插入,與原數據一致
myloader -u automng -p rootroot -h 127.0.0.1 -P 3306 -B vodb -d /data/tmp/table -o -v 3

mysql> select * from test;
+------+--------+---------+------------------------+---------------------+
| tid | tname | test_id | tvalue | CreateTime |
+------+--------+---------+------------------------+---------------------+
| 2 | aaabbb | 3 | 有張有馳有分寸2 | 2018-11-17 21:39:58 |
| 3 | aaabbb | 4 | 有張有馳有分寸3 | 2018-11-17 21:39:58 |
| 4 | aaabbb | 5 | 有張有馳有分寸4 | 2018-11-17 21:39:58 |
+------+--------+---------+------------------------+---------------------+
3 rows in set (0.00 sec)

my21_mydumper與myloader使用