环境信息
canal 1.1.5-snapshot mysql 5.7
问题描述
当库名或表名包含关键字或 - 时抛异常
步骤重现
库名: canal-client-adapter 表名: xdual rdb yml
dataSourceKey: defaultDS destination: example groupId: g1 outerAdapterKey: mysql1 concurrent: true dbMapping: database: retl table: xdual targetDb: canal-client-adapter targetTable: xdual targetPk: id: id mapAll: true # targetColumns: # id: # x: # etlCondition: "where c_time>={}" commitBatch: 3000 # 批量提交的大小
实际执行情况
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-client-adapter.xdual WHERE 1=2' at line 1 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_202] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_202] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_202] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_202] at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.48.jar:5.1.48] at com.mysql.jdbc.Util.getInstance(Util.java:408) ~[mysql-connector-java-5.1.48.jar:5.1.48] at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944) ~[mysql-connector-java-5.1.48.jar:5.1.48] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3933) ~[mysql-connector-java-5.1.48.jar:5.1.48] at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3869) ~[mysql-connector-java-5.1.48.jar:5.1.48] at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524) ~[mysql-connector-java-5.1.48.jar:5.1.48] at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2675) ~[mysql-connector-java-5.1.48.jar:5.1.48] at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465) ~[mysql-connector-java-5.1.48.jar:5.1.48] at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2439) ~[mysql-connector-java-5.1.48.jar:5.1.48] at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1365) ~[mysql-connector-java-5.1.48.jar:5.1.48] at com.alibaba.druid.pool.DruidPooledStatement.executeQuery(DruidPooledStatement.java:230) ~[druid-1.1.9.jar:1.1.9] at com.alibaba.otter.canal.client.adapter.support.Util.sqlRS(Util.java:77) ~[classes/:na] at com.alibaba.otter.canal.client.adapter.rdb.service.RdbSyncService.getTargetColumnType(RdbSyncService.java:420) [client-adapter.rdb-1.1.5-SNAPSHOT-jar-with-dependencies.jar:na] at com.alibaba.otter.canal.client.adapter.rdb.service.RdbSyncService.update(RdbSyncService.java:319) [client-adapter.rdb-1.1.5-SNAPSHOT-jar-with-dependencies.jar:na] at com.alibaba.otter.canal.client.adapter.rdb.service.RdbSyncService.sync(RdbSyncService.java:216) [client-adapter.rdb-1.1.5-SNAPSHOT-jar-with-dependencies.jar:na] at com.alibaba.otter.canal.client.adapter.rdb.service.RdbSyncService.lambda$null$0(RdbSyncService.java:115) [client-adapter.rdb-1.1.5-SNAPSHOT-jar-with-dependencies.jar:na] at java.util.ArrayList.forEach(ArrayList.java:1257) ~[na:1.8.0_202] at com.alibaba.otter.canal.client.adapter.rdb.service.RdbSyncService.lambda$sync$1(RdbSyncService.java:115) [client-adapter.rdb-1.1.5-SNAPSHOT-jar-with-dependencies.jar:na] at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_202] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_202] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_202] at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_202]
原提问者GitHub用户XuDaojie
可通过以下配置解决
dataSourceKey: defaultDS destination: example groupId: g1 outerAdapterKey: mysql1 concurrent: true dbMapping: database: retl table: xdual targetDb: 'canal-client-adapter
' targetTable: xdual targetPk: id: id mapAll: true commitBatch: 3000 # 批量提交的大小
原回答者GitHub用户
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。