溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么使用mysqlbinlog rewrite-db選項(xiàng)

發(fā)布時間:2021-11-18 16:58:35 來源:億速云 閱讀:434 作者:iii 欄目:MySQL數(shù)據(jù)庫

本篇內(nèi)容介紹了“怎么使用mysqlbinlog rewrite-db選項(xiàng)”的有關(guān)知識,在實(shí)際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

5.7中新mysqlbinlog新增加了rewrite-db選項(xiàng),在binlog_format=row時,可以轉(zhuǎn)換庫的名稱: 

在binlog_format=row時,不跨庫 
flush logs; 
use tt; 

mysql> create table c(id int); 
Query OK, 0 rows affected (0.02 sec) 

mysql> insert into c values (1); 
Query OK, 1 row affected (0.01 sec) 

mysql> commit; 
Query OK, 0 rows affected (0.00 sec) 

mysqlbinlog --rewrite-db='tt->test' 1.000002 > /tmp/a.sql 
mysqlbinlog 1.000002 > /tmp/b.sql 

把/tmp/a.sql /tmp/b.sql進(jìn)行對比 
diff /tmp/a.sql /tmp/b.sql 
20c20 
< use `test`/*!*/; 
--- 
> use `tt`/*!*/; 
41c41 
< #160531 21:57:41 server id 1 end_log_pos 488 CRC32 0x1907f678 Table_map: `test`.`c` mapped to number 110 
--- 
> #160531 21:57:41 server id 1 end_log_pos 488 CRC32 0x1907f678 Table_map: `tt`.`c` mapped to number 110 
46c46 
< VZhNVxMBAAAALAAAAOgBAAAAAG4AAAAAAAEABHRlc3QAAWMAAQMAAXj2Bxk= 
--- 
> VZhNVxMBAAAAKgAAAOgBAAAAAG4AAAAAAAEAAnR0AAFjAAEDAAF49gcZ 

在binlog_format=statement時,不跨庫 

mysql> show variables like '%binlog_f%'; 
+---------------+-----------+ 
| Variable_name | Value | 
+---------------+-----------+ 
| binlog_format | STATEMENT | 
+---------------+-----------+ 
mysql> use tt; 
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> drop table c; 
Query OK, 0 rows affected (0.00 sec) 
mysql> flush logs; 
Query OK, 0 rows affected (0.01 sec) 
mysql> create table c(id int); 
Query OK, 0 rows affected (0.02 sec) 

mysql> insert into c values (1); 
Query OK, 1 row affected (0.00 sec) 

diff /tmp/a.sql /tmp/b.sql 
20c20 
< use `test`/*!*/; 
--- 
> use `tt`/*!*/; 

看起來也是可以的。 

但是對于在一個庫中執(zhí)行另外一個庫中的操作 binlog_format=statement就不行了 

mysql> show variables like '%binlog_f%'; 
+---------------+-----------+ 
| Variable_name | Value | 
+---------------+-----------+ 
| binlog_format | STATEMENT | 
+---------------+-----------+ 
mysql> flush logs; 
Query OK, 0 rows affected (0.00 sec) 

mysql> create database song; 
Query OK, 1 row affected (0.01 sec) 

mysql> create table song.a(id int); 
Query OK, 0 rows affected (0.02 sec) 

mysql> insert into song.a values (1); 
Query OK, 1 row affected (0.00 sec) 
[root@10-13-38-7 data]# mysqlbinlog --rewrite-db='song->test' 1.000004 > /tmp/song.sql 
[root@10-13-38-7 data]# mysqlbinlog 1.000004 > /tmp/song_no.sql 
[root@10-13-38-7 data]# diff /tmp/song.sql /tmp/song_no.sql 

結(jié)果是一樣的,所以這時的轉(zhuǎn)換是沒有效果的 
當(dāng)binlog_format=row時,跨庫 
mysql> drop database song; 
Query OK, 1 row affected (0.00 sec) 

mysql> flush logs; 
Query OK, 0 rows affected (0.00 sec) 

mysql> show variables like '%binlog_f%'; 
+---------------+-------+ 
| Variable_name | Value | 
+---------------+-------+ 
| binlog_format | ROW | 
+---------------+-------+ 
1 row in set (0.00 sec) 

mysql> create database song; 
Query OK, 1 row affected (0.00 sec) 

mysql> create table song.a(id int); 
Query OK, 0 rows affected (0.02 sec) 

mysql> insert into song.a values (1); 
Query OK, 1 row affected (0.00 sec) 

[root@10-13-38-7 data]# mysqlbinlog --rewrite-db='song->test' 1.000005 > /tmp/song.sql 
[root@10-13-38-7 data]# mysqlbinlog 1.000005 > /tmp/song_no.sql 
[root@10-13-38-7 data]# diff /tmp/song.sql /tmp/song_no.sql 
48c48 
< #160531 22:19:53 server id 1 end_log_pos 652 CRC32 0xb9ccbd3d Table_map: `test`.`a` mapped to number 114 
--- 
> #160531 22:19:53 server id 1 end_log_pos 652 CRC32 0xb9ccbd3d Table_map: `song`.`a` mapped to number 114 
53c53 
< iZ1NVxMBAAAALAAAAIwCAAAAAHIAAAAAAAEABHRlc3QAAWEAAQMAAT29zLk= 
--- 
> iZ1NVxMBAAAALAAAAIwCAAAAAHIAAAAAAAEABHNvbmcAAWEAAQMAAT29zLk= 

“怎么使用mysqlbinlog rewrite-db選項(xiàng)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI