Search code examples
javamysqljdbcgoogle-cloud-sqlread-replication

MySQL JDBC driver not able to insert data into temporary table on read-replica


I am connecting to read-replica instance of MySQL (actually, Google Cloud SQL). The JDBC driver seems to be able to create temporary table but not able to insert data into it. But, using another client (in my case MySQL workbench), I am able to create and insert data into the temporary table. Looks like a bug in JDBC driver? What are the options to get it working?

Here is the exception I get (I cannot post the entire stacktrace due to company policies):

Caused by: java.sql.SQLException: The MySQL server is running with the --read-only option so it cannot execute this statement
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2468)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2629)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2719)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2450)
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2006)

Version Details:
MySQL version = 5.7.25-google-log
JDBC driver = mysql-connector-java-5.1.21.jar

Note: Running on the master instance (instead of read-replica) will be my last option. I pretty much know it will work.


Solution

  • Tried with recent version of JDBC driver (v5.1.48) and it worked! So there was a bug in the version of JDBC driver I was using earlier (v5.1.21).