The latest and most comprehensive Jmeter interface testing knowledge points in 2024: jmeter connects to the database

jmeter connects to mysql database

The general steps are as follows:

1. Download the jar package of mysql and put it into the lib of jmeter, and then restart jmeter.

2, Deployment JDBC Connection Configuration

3. Configure JDBC Request

4. Reference the queried result variable in the request, and you can combine the counter to get each result value: ${__V(tname_${index})}


1. First, you need to prepare a Mysql jdbc driver package

Try to ensure that its version is consistent with your database version, at least not lower than the database version, otherwise there may be problems.

mysql official website download address:MySQL :: Download Connector/J

The JDBC driver can be downloaded from the official website of mysql: https://dev.mysql.com/downloads/file/?id=477058. No registration is required. Just click on the small words in the lower left corner.

2. Import the JDBC driver package under the test plan, as shown below

 

3. Add a configuration element JDBC Connection Configuration under the thread group.

Variable Name: Custom parameters, used in JDBC Request;

Database URL: jdbc:mysql:// Database IP address: database port/database name; jdbc:mysql://localhost:3306/mysql?serverTimezone=UTC&characterEncoding =utf-8, note:? The following serverTimezone=UTC&characterEncoding=utf-8 cannot be missing, otherwise a time zone error will be reported.

JDBC Driver Class:com.mysql.jdbc.Driver;

Username: database user name;

Password: database password;

4. Add a Sampler: JDBC Request

 4.1. Since the data only needs to be fetched once from the database, that is, the jdbc sampler only needs to be executed once, and the controller can be used only once; as shown below:

Configuration Path: Logical Controller - Only Once Controller

5. After running, the database will return the data under a certain column.

6. Quote the tname variable name in the http request. If a column of data is returned, you can enter ${tname_1} when referencing the variable. The parameter value for sending the request is Zhou Qiyuan

How to use variables names parameter:

The explanation from the Jmeter official website is: If a value is set for this parameter, it will save the data returned by the SQL statement and the total number of rows of the returned data. If the SQL statement returns 2 rows and 3 columns, and the variable names are set to A and C, then the following variables will be set to:

A_#=2 (total number of rows)

A_1=Column 1, row 1; such as the variable ${tname_1} above;

A_2=Column 1, Row 2

C_#=2 (total number of rows)

C_1=Column 3, Row 1

C_2=Column 3, Row 2

If the return result is 0, then A_# and C_# will be set to 0, and other variables will not be set.

If 6 rows of data are returned for the first time and only 3 rows of data are returned for the second time, then the 6 rows of data variables for the first time will be cleared.

You can use ${A_#}, ${A_1}... to get the corresponding value

7. If you want to loop the values ​​returned by the database, you can use a counter and add the referenced variable ${__V(tname_${index})}; as shown below

According to the tname column returned by the database above, there are 9 rows of data. Fill in the maximum value of 9 in the counter and enter a variable name index;

Refer to the variable returned by the data volume + the variable of the counter in the http request:${__V(tname_${index})};

 

8. Operation results

 

  Recommended tutorials related to automated testing:

The latest automated testing self-study tutorial in 2023 is the most detailed tutorial for newbies to get started in 26 days. Currently, more than 300 people have joined major companies by studying this tutorial! ! _bilibili_bilibili

2023 latest collection of Python automated test development framework [full stack/practical/tutorial] collection essence, annual salary after learning 40W+_bilibili_bilibili

Recommended tutorials related to test development

The best in the entire network in 2023, the Byte test and development boss will give you on-site teaching and teach you to become a test and development engineer with an annual salary of one million from scratch_bilibili_bilibili

postman/jmeter/fiddler test tool tutorial recommendation

The most detailed collection of practical tutorials on JMeter interface testing/interface automated testing projects. A set of tutorials for learning jmeter interface testing is enough! ! _bilibili_bilibili

To teach yourself how to capture packets with fiddler in 2023, please be sure to watch the most detailed video tutorial on the Internet [How to Learn to Capture Packets with Fiddler in 1 Day]! ! _bilibili_bilibili

In 2023, the whole network will be honored. The most detailed practical teaching of Postman interface testing at Station B can be learned by novices_bilibili_bilibili

  Summarize:

 Optical theory is useless. You must learn to follow along and practice it in order to apply what you have learned to practice. At this time, you can learn from some practical cases.

If it is helpful to you, please like and save it to give the author an encouragement. It also makes it easier for you to search quickly next time.

If you don’t understand, please consult the small card below. The blogger also hopes to learn and improve with like-minded testers.

At the appropriate age, choose the appropriate position and try to give full play to your own advantages.

My path to automated test development is inseparable from plans at each stage, because I like planning and summarizing.

Test development video tutorials and study notes collection portal! !

Guess you like

Origin blog.csdn.net/m0_59868866/article/details/134629846