jmeter测试mysql
这里只做了插入和查询
1、安装java,jmeter https://jmeter.apache.org/download_jmeter.cgi
2、下载mysql的jar包 https://dev.mysql.com/downloads/connector/j/
3、启动jemeter,设置中文

4、添加jar包,经测试,下载最新的9.0的jar包支持mysql8.0

5、添加线程组

6、添加jdbc链接的配置原件

7、配置数据库
url格式: jdbc:mysql://172.17.0.185:3306/grave?useUnicode=true&serverTimezone=UTC
jdbcDriver下拉框选择

8、添加自定义变量---可选


9、添加插入jdbc request


10、添加查询jdbc request。跟上面一样,只不过query type要选一下

11、添加结果树

12、点击执行


保存这个成xxx.jmx,只需要换一下mysql-connector路径
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.6.3">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan">
<boolProp name="TestPlan.serialize_threadgroups">true</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath">D:\mysql-connector-9.4.0\mysql-connector-j-9.4.0.jar</stringProp>
</TestPlan>
<hashTree>
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="查看结果树">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>true</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<sentBytes>true</sentBytes>
<url>true</url>
<threadCounts>true</threadCounts>
<idleTime>true</idleTime>
<connectTime>true</connectTime>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
<Arguments guiclass="ArgumentsPanel" testclass="Arguments" testname="用户定义的变量">
<collectionProp name="Arguments.arguments">
<elementProp name="username" elementType="Argument">
<stringProp name="Argument.name">username</stringProp>
<stringProp name="Argument.value">${__RandomString(10, abcdefghijklmnopqrstuvwxyz1234567890,)}</stringProp>
<stringProp name="Argument.desc">随机用户名</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="phone" elementType="Argument">
<stringProp name="Argument.name">phone</stringProp>
<stringProp name="Argument.value">${__time(,)}</stringProp>
<stringProp name="Argument.desc">随机手机号</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</Arguments>
<hashTree/>
<JDBCDataSource guiclass="TestBeanGUI" testclass="JDBCDataSource" testname="JDBC Connection Configuration">
<boolProp name="autocommit">true</boolProp>
<stringProp name="checkQuery"></stringProp>
<stringProp name="connectionAge">5000</stringProp>
<stringProp name="connectionProperties"></stringProp>
<stringProp name="dataSource">mysql</stringProp>
<stringProp name="dbUrl">jdbc:mysql://172.17.0.185:3306/grave?useUnicode=true&serverTimezone=UTC</stringProp>
<stringProp name="driver">com.mysql.jdbc.Driver</stringProp>
<stringProp name="initQuery"></stringProp>
<boolProp name="keepAlive">true</boolProp>
<stringProp name="password">b7371d927aec647d</stringProp>
<stringProp name="poolMax">0</stringProp>
<boolProp name="preinit">false</boolProp>
<stringProp name="timeout">10000</stringProp>
<stringProp name="transactionIsolation">DEFAULT</stringProp>
<stringProp name="trimInterval">60000</stringProp>
<stringProp name="username">admin</stringProp>
<stringProp name="TestPlan.comments">mysql连接池</stringProp>
</JDBCDataSource>
<hashTree/>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="mysql插入">
<intProp name="ThreadGroup.num_threads">1</intProp>
<intProp name="ThreadGroup.ramp_time">1</intProp>
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="循环控制器">
<stringProp name="LoopController.loops">1</stringProp>
<boolProp name="LoopController.continue_forever">false</boolProp>
</elementProp>
</ThreadGroup>
<hashTree>
<JDBCSampler guiclass="TestBeanGUI" testclass="JDBCSampler" testname="mysql插入">
<stringProp name="dataSource">mysql</stringProp>
<stringProp name="queryType">Update Statement</stringProp>
<stringProp name="query">INSERT INTO user (
`phone`,
`name`,
`avatar`,
`createTime`,
`firstChange`,
`isBusiness`,
`isBan`
) VALUES (
"${phone}",
"${username}",
2,
${__time(/1000,)},
0,
1,
0
);
</stringProp>
<stringProp name="queryArguments"></stringProp>
<stringProp name="queryArgumentsTypes"></stringProp>
<stringProp name="variableNames"></stringProp>
<stringProp name="resultVariable"></stringProp>
<stringProp name="queryTimeout"></stringProp>
<stringProp name="resultSetMaxRows"></stringProp>
<stringProp name="resultSetHandler">Store as String</stringProp>
</JDBCSampler>
<hashTree/>
</hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="mysql查询">
<intProp name="ThreadGroup.num_threads">1</intProp>
<intProp name="ThreadGroup.ramp_time">1</intProp>
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="循环控制器">
<stringProp name="LoopController.loops">1</stringProp>
<boolProp name="LoopController.continue_forever">false</boolProp>
</elementProp>
</ThreadGroup>
<hashTree>
<JDBCSampler guiclass="TestBeanGUI" testclass="JDBCSampler" testname="mysql查询">
<stringProp name="dataSource">mysql</stringProp>
<stringProp name="query">select * from grave.user;</stringProp>
<stringProp name="queryArguments"></stringProp>
<stringProp name="queryArgumentsTypes"></stringProp>
<stringProp name="queryTimeout"></stringProp>
<stringProp name="queryType">Select Statement</stringProp>
<stringProp name="resultSetHandler">Store as String</stringProp>
<stringProp name="resultSetMaxRows"></stringProp>
<stringProp name="resultVariable"></stringProp>
<stringProp name="variableNames"></stringProp>
<stringProp name="TestPlan.comments">测试查询</stringProp>
</JDBCSampler>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>

浙公网安备 33010602011771号