Java 我有很多选择@@session.tx_只读,有人会这样做吗?
我使用Python通过其他人用Java编写的API在数据库中插入值。插入速度非常慢,当我查看一次插入的TransActions的mysql日志时,我发现它通常会选择@@session.tx_read_:Java 我有很多选择@@session.tx_只读,有人会这样做吗?,java,mysql,Java,Mysql,我使用Python通过其他人用Java编写的API在数据库中插入值。插入速度非常慢,当我查看一次插入的TransActions的mysql日志时,我发现它通常会选择@@session.tx_read_: | 2015-09-04 10:53:51 | INSERT INTO `InterestTable` (`added_by`, `datetime_added`, `datetime_last_updated`, `updated_by`, `accuracy`, `average_repor
| 2015-09-04 10:53:51 | INSERT INTO `InterestTable` (`added_by`, `datetime_added`, `datetime_last_updated`, `updated_by`, `accuracy`, `average_reported_quality`, `empirical_quality`) VALUES ('admin', '2015-09-04 10:53:50.502649', null, null, 42.28, 43.0)
| 2015-09-04 10:53:51 | select @@session.tx_read_only
| 2015-09-04 10:53:51 | select @@session.tx_read_only
| 2015-09-04 10:53:51 | UPDATE `muloTransactionLog` SET `transactionId` = 'aaaact4xr7lus7v3ina5bgyaae', `userName` = 'admin', `startTime` = '2015-09-04', `transactionStatus` = 'COMMITED', `endTime` = '2015-09-04' WHERE `transactionId`= 'aaaact4xr7lus7v3ina5bgyaae'
| 2015-09-04 10:53:51 | select @@session.tx_read_only
| 2015-09-04 10:53:51 | select @@session.tx_read_only
| 2015-09-04 10:53:51 | commit
| 2015-09-04 10:53:51 | SET autocommit=1
| 2015-09-04 10:53:51 | SHOW FULL TABLES FROM `db` LIKE 'PROBABLYNOT'
| 2015-09-04 10:53:52 | SET autocommit=0
| 2015-09-04 10:53:52 | select @@session.tx_read_only
| 2015-09-04 10:53:52 | select @@session.tx_read_only
| 2015-09-04 10:53:52 | INSERT INTO `muloTransactionLog` (`transactionId`, `userName`, `startTime`, `transactionStatus`, `endTime`) VALUES ('aaaact4xr7omm7v3ina5bgyaae', 'g3943', '2015-09-04', 'STARTED', null)
| 2015-09-04 10:53:53 | select @@session.tx_read_only
| 2015-09-04 10:53:53 | select @@session.tx_read_only
| 2015-09-04 10:53:53 | INSERT INTO `muloTransactionLogEntry` (`id`, `muloTransactionLog`, `entity`, `type`) VALUES ('AAAACT4XR7PWQ7V3INA5BGYAAE', 'aaaact4xr7omm7v3ina5bgyaae', 'InterestTable', 'ADD')
| 2015-09-04 10:53:53 | select @@session.tx_read_only
| 2015-09-04 10:53:53 | select @@session.tx_read_only
从我的猜测来看,它的使用是为了避免同时书写和阅读,但我没有看到它再次被关闭。因此,它只能使用一次并具有相同的效果,如下所示:
| 2015-09-04 10:53:51 | INSERT INTO `InterestTable` (`added_by`, `datetime_added`, `datetime_last_updated`, `updated_by`, `accuracy`, `average_reported_quality`, `empirical_quality`) VALUES ('admin', '2015-09-04 10:53:50.502649', null, null, 42.28, 43.0)
| 2015-09-04 10:53:51 | select @@session.tx_read_only
| 2015-09-04 10:53:51 | UPDATE `muloTransactionLog` SET `transactionId` = 'aaaact4xr7lus7v3ina5bgyaae', `userName` = 'admin', `startTime` = '2015-09-04', `transactionStatus` = 'COMMITED', `endTime` = '2015-09-04' WHERE `transactionId`= 'aaaact4xr7lus7v3ina5bgyaae'
| 2015-09-04 10:53:51 | commit
| 2015-09-04 10:53:51 | SET autocommit=1
| 2015-09-04 10:53:51 | SHOW FULL TABLES FROM `db` LIKE 'PROBABLYNOT'
| 2015-09-04 10:53:52 | SET autocommit=0
| 2015-09-04 10:53:52 | INSERT INTO `muloTransactionLog` (`transactionId`, `userName`, `startTime`, `transactionStatus`, `endTime`) VALUES ('aaaact4xr7omm7v3ina5bgyaae', 'g3943', '2015-09-04', 'STARTED', null)
| 2015-09-04 10:53:53 | INSERT INTO `muloTransactionLogEntry` (`id`, `muloTransactionLog`, `entity`, `type`) VALUES ('AAAACT4XR7PWQ7V3INA5BGYAAE', 'aaaact4xr7omm7v3ina5bgyaae', 'InterestTable', 'ADD')
如果可以的话,我应该在哪里改变这个当我试图选择并随后插入到同一个表中时,我遇到了同样的问题。一旦从表中选择,服务器似乎会在其上保持
tx\u read\u
锁定,直到发生提交。如果在提交之前尝试插入或更新,则事务将被忽略
tl;博士确保在python中设置连接时启用了自动提交
编辑:我发现了有关事务和提交的更多细节。我在尝试选择并随后插入到同一个表时遇到了同样的问题。一旦从表中选择,服务器似乎会在其上保持
tx\u read\u
锁定,直到发生提交。如果在提交之前尝试插入或更新,则事务将被忽略
tl;博士确保在python中设置连接时启用了自动提交
编辑:我发现了更多关于事务和提交的细节。这是因为MySQL JDBC驱动程序的默认值
useSessionStatus
为false
。每次驱动程序需要检查目标数据库的isReadOnly
状态时,它都会向服务器发送select@@session.tx\u readonly
。将useSessionStatus
设置为true
将使用连接对象的本地状态
删除此查询的最简单方法是将
&useLocalSessionState=true
附加到JDBC连接字符串。这是因为MySQL JDBC驱动程序的默认值useSessionStatus
为false
。每次驱动程序需要检查目标数据库的isReadOnly
状态时,它都会向服务器发送select@@session.tx\u readonly
。将useSessionStatus
设置为true
将使用连接对象的本地状态
删除此查询的最简单方法是将&useLocalSessionState=true
附加到JDBC连接字符串