我正试图给TIDB (Spark2.3)写一条电火花数据(百万行)。
df.write.format('jdbc').options(
url='jdbc:mysql://<host>:<port>/<table>',
driver='com.mysql.jdbc.Driver',
dbtable='<tablename>',
user='<username>',
password='<password>',
batchsize = 30000,
truncate = True
).mode('overwrite').save()然而,我一直得到的就是这个错误
Caused by: java.sql.BatchUpdateException: statement count 5001 exceeds the transaction limitation, autocommit = false
....
....
....
Caused by: java.sql.SQLException: statement count 5001 exceeds the transaction limitation, autocommit = false知道我该怎么解决这个问题吗?
发布于 2019-12-29 17:02:58
应该将?rewriteBatchedStatements=true添加到JDBC中,以便批处理DML语句。不仅写入速度会更快,而且不会那么容易地达到数据库事务限制。
发布于 2021-12-15 12:07:31
您可以尝试添加选项,将"isolationLevel“设置为”无“,这将避免事务的限制。
df.write.format('jdbc').options(
url='jdbc:mysql://<host>:<port>/<table>',
driver='com.mysql.jdbc.Driver',
dbtable='<tablename>',
user='<username>',
password='<password>',
batchsize = 30000,
truncate = True,
isolationLevel = None
).mode('overwrite').save()https://stackoverflow.com/questions/59520631
复制相似问题