欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

TIDB作为mysql的从库使用

程序员文章站 2022-07-13 10:02:57
...

1,TIDB安装部署

link

2,全量数据同步:

下载官方同步工具

[[email protected] ~]# wget http://download.pingcap.org/tidb-latest-linux-amd64.tar.gz
[[email protected] ~]# tar xvf tidb-latest-linux-amd64.tar.gz
[[email protected] ~]# mv tidb-latest-linux-amd64 tidb-tool
[[email protected] ~]# cd tidb-tool/bin/
[[email protected] ~]# ./mydumper -h 192.168.50.2 -P 3306 -u root -p 123456 -t 16 -F 128 --regex '^(?!(mysql|sys))' -o ./test
全量导出数据,排除mysql,sys,默认会自动排除information_schema和performance_schema两个库

3,导入全量数据:

[[email protected] ~]# ./loader -u root -p 123456 -h 192.168.50.31 -P 4000 -t 16 -d ./test

4,增量数据导入:

[[email protected] test]# cat metadata 
Started dump at: 2019-04-11 16:10:41
SHOW MASTER STATUS:
        Log: mysql-bin.000034
        Pos: 395907578
        GTID:4a5463b4-4ae5-11e9-b149-fa163ea5920b:1-114098

SHOW SLAVE STATUS:
        Host: 192.168.61.3
        Log: 
        Pos: 0
        GTID:4a5463b4-4ae5-11e9-b149-fa163ea5920b:1-114098

Finished dump at: 2019-04-11 16:15:33

[[email protected] bin]# vi syncer.meta     #新建syncer.meta文件,降对应的binlog信息填入
binlog-name = "mysql-bin.000034"
binlog-pos = 395907578
binlog-gtid = "4a5463b4-4ae5-11e9-b149-fa163ea5920b:1-114098"

[[email protected] bin]# cat config.toml    #新建syncer的配置文件config.toml
log-level = "info"
log-file = "syncer.log"
log-rotate = "day"

server-id = 101

[from]
host = "192.168.50.2"
user = "root"
password = "123456"
port = 3306

[to]
host = "192.168.50.31"
user = "root"
password = "123456"
port = 4000
   
[[email protected] bin]# ./syncer -config config.toml --enable-gtid         #启动同步进程
[2019/04/11 16:48:38] [info] binlogsyncer.go:132 create BinlogSyncer with config {101 mysql 192.168.50.2 3306 root    false false <nil> false UTC true 0 30s 1m0s 0 false}
[2019/04/11 16:48:38] [info] binlogsyncer.go:364 begin to sync binlog from GTID set 4a5463b4-4ae5-11e9-b149-fa163ea5920b:1-114098
[2019/04/11 16:48:38] [info] binlogsyncer.go:195 register slave for master server 192.168.50.2
[2019/04/11 16:48:38] [info] binlogsyncer.go:715 rotate to (mysql-bin.000034, 4)

5,验证同步是否正常

[[email protected] bin]# mysql -uroot -p123 -h192.168.50.2 -e "use test;delete from tt_test where id=1;"   #在原库删除数据
[[email protected] bin]# mysql -uroot -p123 -h192.168.50.31 -P4000
mysql> use test;
Database changed
mysql> select * fro tt_test limit 1;

小结:syncer在使用过程中,如果遇到同步一场,会立刻退出程序,没有异常处理机制,如果在生产上使用还是建议使用官方的DM工具。