1、canal
a、数据库设置
1.在/etc/my.cmf文件下添加以下三句话:
log-bin = mysql-bin
binlog-format=Row
binlog_row_image = FULL (默认就是FULL不配也可以,出现数据字段丢失,就必须要配置)
server-id=1
关于:binlog_row_image参数的说明:https://blog.csdn.net/actiontech/article/details/81701362
在数据库查看
show master status
show master logs
show binary logs ;
show binlog events in 'mysql-bin.000012';
show variables like 'binlog_format'; ROW
show variables like '%server_id%';
show variables like 'log_bin';
2.在数据库中创建用户:
CREATE USER canal IDENTIFIED BY 'canal';
GRANT SELECT,REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'canal'@'localhost' IDENTIFIED BY 'canal';
FLUSH PRIVILEGES;
b、canal配置
参考: https://blog.csdn.net/u013151053/article/details/84331800
(1) vi canal.properties 配置canal
canal.ip= localhost
canal.port= 11111
canal.serverMode = kafka
canal.mq.servers = localhost:9092
(2) vi/example/instance.properties配置数据库
canal.instance.mysql.slaveId= 1234
canal.instance.dbUsername= 数据库用户
canal.instance.dbPassword= 数据库用户密码
canal.mq.topic= kafka的topic
c、启动
(1)重启数据库
(2)./bin/startup.sh
d、高级设置
(1)过滤数据库和表的
设置: conf/example/instance.properties文件的 canal.instance.filter.regex=
1. 所有表:.* or .*\\..*
2. canal schema下所有表: canal\\..* (canal为数据库)
3. canal下的以canal打头的表:canal\\.canal.*
4. canal schema下的一张表:canal.test1
5. 多个规则组合使用:canal\\..*,mysql.test1,mysql.test2 (逗号分隔)
(2)发往topic
设置: conf/example/instance.properties文件的 canal.mq.dynamicTopic=
canal 1.1.3版本之后, 支持配置格式:schema 或 schema.table,多个配置之间使用逗号或分号分隔
- 例子1:test\\.test 指定匹配的单表,发送到以test_test为名字的topic上
- 例子2:.*\\..* 匹配所有表,则每个表都会发送到各自表名的topic上
- 例子3:test 指定匹配对应的库,一个库的所有表都会发送到库名的topic上
- 例子4:test\\.* 指定匹配的表达式,针对匹配的表会发送到各自表名的topic上
- 例子5:test,test1\\.test1,指定多个表达式,会将test库的表都发送到test的topic上,test1\\.test1的表发送到对应的test1_test1 topic上,其余的表发送到默认的canal.mq.topic值
为满足更大的灵活性,允许对匹配条件的规则指定发送的topic名字,配置格式:topicName:schema 或 topicName:schema.table
- 例子1: test:test\\.test 指定匹配的单表,发送到以test为名字的topic上
- 例子2: test:.*\\..* 匹配所有表,因为有指定topic,则每个表都会发送到test的topic下
- 例子3: test:test 指定匹配对应的库,一个库的所有表都会发送到test的topic下
- 例子4:testA:test\\.* 指定匹配的表达式,针对匹配的表会发送到testA的topic下
- 例子5:test0:test,test1:test1\\.test1,指定多个表达式,会将test库的表都发送到test0的topic下,test1\\.test1的表发送到对应的test1的topic下,其余的表发送到默认的canal.mq.topic值
canal.mq.dynamicTopic | canal.instance.filter.regex | 发送topic | 描述 |
.\..* | d1.t,d2.t,d3.t | d1,d2,d3 | 同一个数据库发送到以数据库为名字的topic |
.\...* | d1.t,d2.t,d3.t | d1,d2,d3 | 同一个数据库发送到以数据库为名字的topic |
.*\\..* | d1.t,d2.t,d3.t | d1_t,d2_t,d3_t | 单表单topic,数据库和表名为topic |
t:d.*\\.t | d1.t,d2.t,d3.t | t | 不同库同表,以表名为topic |
支持指定topic名称匹配, 配置格式:topicName:schema 或 schema.table,多个配置之间使用逗号分隔, 多组之间使用 ; 分隔
e、canal 的高可用
2、数据库
a、删除旧的
1、查看看旧的版本
rpm -qa |grep mysql
2、删除旧的版本
rpm -e mysql-5.1.73-8.el6_8.x86_64
rpm -e mysql-libs-5.1.73-8.el6_8.x86_64 --nodeps
/var/log/mysqld.log saved as /var/log/mysqld.log.rpmsave
b、安装mysql
1、下载rpm安装包(mysql-5.7.26-1.el6.x86_64.rpm-bundle.tar)
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.26-1.el6.x86_64.rpm-bundle.tar
将mysql-5.7.26-1.el6.x86_64.rpm-bundle.tar解压到一个指定的文件中
tar -xvf mysql-5.7.26-1.el6.x86_64.rpm-bundle.tar
2、安装server
rpm -ivh mysql-community-common-5.7.26-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.26-1.el6.x86_64.rpm
rpm -ivh mysql-community-client-5.7.26-1.el6.x86_64.rpm
rpm -ivh mysql-community-server-5.7.26-1.el6.x86_64.rpm
3、安装
(1)启动服务service mysqld restart
(2)找密码:去/var/log/mysqld.log
[Note] A temporary password is generated for root@localhost: -yr-x>r:-6Jz
这一句中:用户名:root 密码:-yr-x>r:-6Jz
4、登录修改密码
mysql -uroot -p 再输入 -yr-x>r:-6Jz
set password for root@localhost = password('root');
c、mysql的备份
备份:
mysqldump -h主机名 -P端口 -u用户名 -p密码 –B 数据库名 > 文件名.sql
mysqldump -hhadoop -P3306 -uroot -proot2018! -database stk >test.sql
导入:
mysql -hhadoop -P3306 -uroot -proot2018! ODS< test.sql