简体   繁体   English

没有编程脚本,如何在MySql中模拟死锁?

[英]How do I simulate a deadlock in MySql without programming scripts?

It's sometimes useful to be able to simulate a deadlock in a database (such as MySQL) for testing purposes. 能够模拟数据库(例如MySQL)中的死锁以进行测试有时很有用。 If you have write access to the database, you can simulate the deadlock by starting a write transaction on a table another query will attempt to use. 如果您具有对数据库的写访问权,则可以通过在另一个查询将尝试使用的表上启动写事务来模拟死锁。

  1. Log onto the database 登录数据库
  2. Start a transaction begin; 开始交易begin;
  3. Lock the table with an update statement that modifies all rows in the table update <table> set <column>=<value>; 用一条更新语句锁定表,该语句修改表中的所有行update <table> set <column>=<value>;
  4. All other applications will encounter the table as being locked until you commit or rollback the transaction. 在提交或回滚事务之前,所有其他应用程序都将表锁定。
  5. To end the deadlock, rollback the transaction. 要结束僵局,请回滚事务。 rollback;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM