使用shardingsphere-proxy 4.1.1版本
问题1:使用spark读取不到mysql表的数据
mysql分库后,mysql url改为shardingsphere代理的地址.
然后发现原来执行的spark.read.format("jdbc").options(...)load()程序,突然读不到mysql表的数据了
原因和解决方法
- url地址如下,包含了的开启预编译参数:useServerPrepStmts
jdbc:shardingsphere-proxy:8888://mysql:3306/mydb?useServerPrepStmts=true - 关闭后读取mysql正常,但会影响一些性能:useServerPrepStmts=false
问题2:1Unsupported command: [COM_SET_OPTION]
- mysql jdbc执行批量更新或删除操作时,如果batch条数在5条及以上(5条以下,会被msyql自动优化为单条提交),会报错:1Unsupported command: [COM_SET_OPTION]
- 去掉批量参数,同样会降低影响写入性能:rewriteBatchedStatements=false
最终解决方案:
- 查阅github中的issue,以上两个问题,在最新的5.1.1版本已经被修复
- 部署shardingsphere-proxy 5.1.1版本后,添加useServerPrepStmts=true&useServerPrepStmts=true,测试读写mysql正常
补充:
开发过程中,使用带有占位符的批量更新语句,遇到一个报错,感觉莫名其妙,反复检查sql语句和参数,均没有发现问题。
java.lang.Exception: java.sql.BatchUpdateException: 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
最终发现是预编译的sql语句结尾有分号导致的,去掉分号后恢复正常