分享mysql压力测试脚本
SQL #mysql #压力测试2012-11-17 22:06
001 | #创建表DEPT |
002 |
003 | CREATE TABLE dept( /*部门表*/ |
004 | deptno MEDIUMINT UNSIGNED NOT NULL DEFAULT 0, |
005 | dname VARCHAR(20) NOT NULL DEFAULT "" , |
006 | loc VARCHAR(13) NOT NULL DEFAULT "" |
007 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; |
008 |
009 | #创建表EMP雇员 |
010 | CREATE TABLE emp |
011 | (empno MEDIUMINT UNSIGNED NOT NULL DEFAULT 0, |
012 | ename VARCHAR(20) NOT NULL DEFAULT "" , |
013 | job VARCHAR(9) NOT NULL DEFAULT "" , |
014 | mgr MEDIUMINT UNSIGNED NOT NULL DEFAULT 0, |
015 | hiredate DATE NOT NULL, |
016 | sal DECIMAL(7,2) NOT NULL, |
017 | comm DECIMAL(7,2) NOT NULL, |
018 | deptno MEDIUMINT UNSIGNED NOT NULL DEFAULT 0 |
019 | )ENGINE=MyISAM DEFAULT CHARSET=utf8 ; |
020 |
021 | #工资级别表 |
022 | CREATE TABLE salgrade |
023 | ( |
024 | grade MEDIUMINT UNSIGNED NOT NULL DEFAULT 0, |
025 | losal DECIMAL(17,2) NOT NULL, |
026 | hisal DECIMAL(17,2) NOT NULL |
027 | )ENGINE=MyISAM DEFAULT CHARSET=utf8; |
028 |
029 | INSERT INTO salgrade VALUES (1,700,1200); |
030 | INSERT INTO salgrade VALUES (2,1201,1400); |
031 | INSERT INTO salgrade VALUES (3,1401,2000); |
032 | INSERT INTO salgrade VALUES (4,2001,3000); |
033 | INSERT INTO salgrade VALUES (5,3001,9999); |
034 |
035 | # 随机产生字符串 |
036 | #定义一个新的命令结束符合 |
037 | delimiter $$ |
038 | #删除自定的函数 |
039 | drop function rand_string $$ |
040 |
041 | #这里我创建了一个函数. |
042 |
043 | create function rand_string(n INT) |
044 | returns varchar(255) |
045 | begin |
046 | declare chars_str varchar(100) default |
047 | 'abcdefghijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ' ; |
048 | declare return_str varchar(255) default '' ; |
049 | declare i int default 0; |
050 | while i < n do |
051 | set return_str =concat(return_str,substring(chars_str,floor(1+rand()*52),1)); |
052 | set i = i + 1; |
053 | end while ; |
054 | return return_str; |
055 | end $$ |
056 |
057 |
058 | delimiter ; |
059 | select rand_string(6); |
060 |
061 | # 随机产生部门编号 |
062 | delimiter $$ |
063 | drop function rand_num $$ |
064 |
065 | #这里我们又自定了一个函数 |
066 | create function rand_num( ) |
067 | returns int(5) |
068 | begin |
069 | declare i int default 0; |
070 | set i = floor(10+rand()*500); |
071 | return i; |
072 | end $$ |
073 |
074 |
075 | delimiter ; |
076 | select rand_num(); |
077 |
078 | #****************************************** |
079 | #向emp表中插入记录(海量的数据) |
080 |
081 |
082 | delimiter $$ |
083 | drop procedure insert_emp $$ |
084 |
085 | create procedure insert_emp( in start int(10), in max_num int(10)) |
086 | begin |
087 | declare i int default 0; |
088 | set autocommit = 0; |
089 | repeat |
090 | set i = i + 1; |
091 | insert into emp values ((start+i) ,rand_string(6), 'SALESMAN' ,0001,curdate(),2000,400,rand_num()); |
092 | until i = max_num |
093 | end repeat; |
094 | commit; |
095 | end $$ |
096 |
097 |
098 | delimiter ; |
099 | #调用刚刚写好的函数, 1800000条记录,从100001号开始 |
100 | call insert_emp(100001,1800000); |
101 |
102 |
103 | #************************************************************** |
104 | # 向dept表中插入记录 |
105 |
106 | delimiter $$ |
107 | drop procedure insert_dept $$ |
108 |
109 |
110 | create procedure insert_dept( in start int(10), in max_num int(10)) |
111 | begin |
112 | declare i int default 0; |
113 | set autocommit = 0; |
114 | repeat |
115 | set i = i + 1; |
116 | insert into dept values ((start+i) ,rand_string(10),rand_string(8)); |
117 | until i = max_num |
118 | end repeat; |
119 | commit; |
120 | end $$ |
121 |
122 |
123 | delimiter ; |
124 | call insert_dept(100,10); |
125 |
126 | #------------------------------------------------ |
127 | #向salgrade 表插入数据 |
128 | delimiter $$ |
129 | drop procedure insert_salgrade $$ |
130 | create procedure insert_salgrade( in start int(10), in max_num int(10)) |
131 | begin |
132 | declare i int default 0; |
133 | set autocommit = 0; |
134 | ALTER TABLE emp DISABLE KEYS; |
135 | repeat |
136 | set i = i + 1; |
137 | insert into salgrade values ((start+i) ,(start+i),(start+i)); |
138 | until i = max_num |
139 | end repeat; |
140 | commit; |
141 | end $$ |
142 | delimiter ; |
143 | #测试不需要了 http://yige.org |
144 | #call insert_salgrade(10000,1000000); |
145 |
146 | #---------------------------------------------- |
相关文章
- SQL Server在特定时间范围内按时间段查询 2012/11/14
- DMX-SQL SERVER 数据挖掘简介 2012/11/14
- SQL Server之SQL的分页加排序等写法 2012/11/02
- MySQL通过命令导入导出数据的方法 2012/10/29
- 基于MySQL的BBS数据库设计教程 2012/10/29
- 关系数据库设计范式深入浅出 2012/10/29
- SQL截取字符串的方法 2012/10/25
- SQL Server删除重复数据的几个方法 2012/10/24
- SQL Server导入导出 2012/10/24
- SQL Server常用技巧 2012/10/24