准备环境
1、 mysql安装
2、mysql开启binglog写入功能,配置binglog-format为row模式,my.cnf配置如下
[mysqld]
log-bin=mysql-bin # 开启 binlog
binlog-format=ROW # 选择 ROW 模式
server_id=1 # 配置 MySQL replaction 需要定义,不要和 canal 的 slaveId 重复
3、单独添加canal账户,并分配slave权限,命令如下
CREATE USER canal IDENTIFIED BY 'canal';
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
-- GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%' ;
FLUSH PRIVILEGES;
安装canal(参考官网: https://github.com/alibaba/canal/wiki/QuickStart )
1、下载canal,访问https://github.com/alibaba/canal/releases,选择合适的版本
wget https://github.com/alibaba/canal/releases/download/canal-1.0.17/canal.deployer-1.0.17.tar.gz
2、解压缩
mkdir /tmp/canal
tar zxvf canal.deployer-$version.tar.gz -C /tmp/canal
3、修改配置(即配置binglog数据消费队列,可增加多个example文件夹)
vi conf/example/instance.properties
canal.instance.master.address=mysql:port
canal.instance.dbUsername=canal
canal.instance.dbPassword=canal
canal.instance.connectionCharset = UTF-8
4、启动、关闭
#启动
sh bin/startup.sh
#关闭
sh bin/stop.sh
5、观察server和instance日志
tailf logs/canal/canal.log
tailf logs/example/example.log
错误记录:
tailf logs/example/example.log 有以下错误日志
Can't read dir of './performance_schema/' (errno: 13 - Permission denied)
show full tables from `performance_schema` where Table_type = 'BASE TABLE'
在myslq执行:
show full tables from `performance_schema` where Table_type = 'BASE TABLE'
报错如下:
ERROR 1018 (HY000): Can't read dir of './performance_schema/' (errno: 13 - Permission denied)
原因:performance_schema 文件,对应的mysql用户没有操作权限
解决:
chown -R mysql:mysql /var/lib/mysql/performance_schema/