测试 MySQL 查询 [英] Testing MySQL Query

查看:50
本文介绍了测试 MySQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

测试mysql查询的正确方法是什么?

What is the right method to testing mysql query?

示例:我想测试运行更新查询

Example: i want to testing running update query

update `transaction` set date="2013-01-01" where id=1;

查询更新后,我看到数据库正确更改.但随后我希望数据库恢复到执行查询更新之前的状态,因为查询目的仅用于测试.

after the query update, i see the database is change correctly. but then i want the database revert back to the state before the query update execute, because that's query purpose is for testing only.

是否有任何工具可以轻松创建虚拟数据库进行测试,或者 mysql 是否具有恢复状态的功能?

Is there any tools to easily create virtual database to testing or maybe mysql have functions to revert back the state?

推荐答案

正如 Barmar 建议的那样.使用测试数据库.但是,如果您对实时数据库进行了可怕的更改并在测试数据库上对其进行了测试,那么您可以放心使用事务来确认实时更改是否符合您的预期.为此,您可以使用事务.

As Barmar suggested. Use a test database. However if you're making a scary change to a live database and have tested it on a test database it can set your mind at ease to use transactions to confirm the live changes are as you expect. For this you can use transactions.

START TRANSACTION;
UPDATE foo SET baz = "bar";
SELECT baz FROM foo;-- Shows bar
ROLLBACK; -- Alternatively 'COMMIT'
SELECT baz FROM foo;-- Shows whatever was there previously.

请注意,对架构的更改不是事务性的(即无法回滚更改表).

Note that changes to schema are not transactional (i.e. altering tables cannot be rolled back).

这篇关于测试 MySQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆