如何在 MySQL 上模拟长时间运行的更改查询

我有一个系统,我想测试它执行 Alter 查询。我正在寻找一种方法来模拟长时间运行的 Alter 查询,我可以在它运行时测试“恐慌”、“资源使用情况”、“并发性”等。

是否有任何方法可以模拟长时间运行的 Alter 查询?

我正在使用 gh-ost 进行更改执行。

zhourqdl 回答:如何在 MySQL 上模拟长时间运行的更改查询

当我想测试长时间运行的 ALTER TABLE 时,我会这样做:

  1. 创建表格。

  2. 用几百万行随机数据填充它,直到它足够大以至于 ALTER TABLE 需要几分钟。需要多少行取决于您的计算机速度。

  3. 在其上运行 ALTER TABLE。

我没有找到更好的解决方案,而且我从 2001 年就开始使用 MySQL。

这是一个无需客户端应用程序或脚本即可填充大量行的技巧:

mysql> create table mytable (id int auto_increment primary key,t text);
Query OK,0 rows affected (0.05 sec)

mysql> insert into mytable (t) select repeat(sha1(rand()),255) from dual;
Query OK,1 row affected (0.02 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into mytable (t) select repeat(sha1(rand()),255) from mytable;
Query OK,1 row affected (0.03 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into mytable (t) select repeat(sha1(rand()),2 rows affected (0.02 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> insert into mytable (t) select repeat(sha1(rand()),4 rows affected (0.03 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> insert into mytable (t) select repeat(sha1(rand()),8 rows affected (0.03 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql> insert into mytable (t) select repeat(sha1(rand()),16 rows affected (0.03 sec)
Records: 16  Duplicates: 0  Warnings: 0

现在我有 32 行(16+8+4+2+1+1)。我可以根据需要多次继续相同的查询,每次都会使表的大小增加一倍。很快我就有了一张几 GB 的表 大小。

本文链接:https://www.f2er.com/21238.html

大家都在问