Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What if the transaction cannot be rolled back when executing the database?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article shares information about what to do if a transaction cannot be rolled back while performing a database 'INSERT' operation. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

When using Spring declarative transactions, I found that when doing "update", abnormal transactions can be rolled back, but when executing "insert", although the background log shows that the rollback, but the data has been saved to the database, originally thought that there is a configuration error, but later found that it is Mysql storage engine problems. The Mysql version we are using is "5.1.73" and the default storage engine is "MyISAM."

mysql> select version();+---------+| version() |+-----------+| 5.1.73 |+-----------+1 row in set (0.00 sec) View mysql storage engines mysql> SHOW ENGINES;+------------+---------+------------------------------------------------------------+--------------+------+------------+| Engine | Support | Comment | Transactions | XA | Savepoints |+------------+---------+------------------------------------------------------------+--------------+------+------------+| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO || CSV | YES | CSV storage engine | NO | NO | NO || MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO || InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES || MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |+------------+---------+------------------------------------------------------------+--------------+------+------------+5 rows in set (0.00 sec)

The reason is clear here. The default is "MyISAM" when creating tables. The difference between "MyISAM" and "InnoDB" and other storage engines is not expanded here. We only need to change the storage engine of our tables to "InnoDB".

SHOW TABLE STATUS FROM database;ALTER TABLE table_name ENGINE = InnoDB;mysql> ALTER TABLE table_name ENGINE = InnoDB;Query OK, 8 rows affected (0.03 sec)Records: 8 Duplicates: 0 Warnings: 0

If it is a master repository, it is best to change the default storage engine to "InnoDB"...

Thank you for reading! About "how to do when the transaction cannot be rolled back when performing the database 'INSERT' operation" This article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report