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

613 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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).

2
On

No, the driver version is by 99% not the problem cause (I guess). Because I wrote to temporary tables successfully on MySQL 5.0, 5.1, 5.6 and 5.7 with the matching JDBC driver version.

The error message tells me that the server itself is rejecting the attempt due to its "read only" configuration.

There is a related bug report: https://bugs.mysql.com/bug.php?id=64992

Are you sure that you table is really a temporary one (not a regular table) and that you are using it within the same session/connection? Because otherwise it does not work on purpose.