我们在GKE上部署了一个微服务,通过云sql代理连接到GCP上的mysql db实例。我们使用spring jdbctemplate。batchUpdate执行批插入/更新语句。当我追加rewriteBatchStatements=true jdbc url jdbc:mysql://localhost:3306/db?rewriteBatchStatements=true,无法连接到数据库实例
最后一个成功发送到服务器的数据包是0毫秒前。驱动程序没有收到来自服务器的任何数据包。在java.base/jdk.internal.reflect.Native econstructoraccessorimpl . newinstance0(本地方法)在java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java: 62)在java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java: 45)在java.base/java.lang.reflect.Constructor.newInstance (Constructor.java: 490)com.mysql.cj.exceptions.ExceptionFactory.createException (ExceptionFactory.java: 61)com.mysql.cj.exceptions.ExceptionFactory.createException (ExceptionFactory.java: 105)com.mysql.cj.exceptions.ExceptionFactory.createException (ExceptionFactory.java: 151)com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException (ExceptionFactory.java: 167)com.mysql.cj.protocol.a.NativeSocketConnection.connect (NativeSocketConnection.java: 91)com.mysql.cj.NativeSession.connect (NativeSession.java: 144)com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly (ConnectionImpl.java: 956)com.mysql.cj.jdbc.ConnectionImpl.createNewIO (ConnectionImpl.java: 826)…省略40个常用框架java.net.ConnectException: Connection refused (Connection refused)在java.base/java.net.PlainSocketImpl.socketConnect(本机方法)在java.base/java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java: 399)在java.base/java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java: 242)在java.base/java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java: 224)
如何启用rewriteBatchStatements?
此异常是由于GKE中缺少云代理的服务条目。jdbc: mysql://localhost: 3306/db吗?rewriteBatchStatements=true works fine