Table of Contents
- Introduction
- System Requirement
- Step 1: Launch Jmeter.
- Step 2: Download MySQL Connector
- Step 3: Unzip and save MySQL Connector
- Step 4: Now Restart JMeter
- Step 5 : Create JMeter Thread Group
- Step 6: Setup Thread Group
- Step 7 : Add JDBC Config Element for JMeter
- Step 8: Setup database configuration
- Step 9: Add JDBC Request Sampler in JMeter
- Step 10: Prepare SQL query
- Step 11: Update JDBC connection name
- Step 12: Add ‘Results in Table’ listner to script
- Step 13: Add ‘View Results Tree’ Listner
- Step 14: Run your jmeter script
- Step 15: View Results Table and Tree
Introduction
In this ‘How-To’, You will be guided to perform a database load test using JMeter. We will be installing Apache JMeter to perform the test. You can download Apache Jmeter from this link as your first step and keep it ready for further steps to follow where we shall be creating, running and analyzing simple demo-based database test script using JMeter.
System Requirement
We would be using the following tools for this exercise:
- Apache JMeter 5.2.1
- Mysql-connector-java-8.0.20
- MySQL Database (local install or cloud provisioned instance from db4free.net)
- We are running these exercises on local windows OS machine.
Step 1: Launch Jmeter.
You can run JMeter using the “ApacheJMeter.jar” file which is in the “bin” folder. Here is a screenshot of JMeter GUI :
Step 2: Download MySQL Connector
We use the Mysql database to create our testing Database. First, you have to connect the MySQL database with JMeter using MySQL connector. First, navigate to MySQL Website and download the zip folder as shown in the image below :
Step 3: Unzip and save MySQL Connector
Extract the zip folder and Copy “Mysql-connector-java-8.0.20.jar” file (Version may differ) from the folder and paste it into the “lib” folder of JMeter.
Step 4: Now Restart JMeter
Restart the JMeter so that it will work with the library provided by MySQL connector.
Step 5 : Create JMeter Thread Group
Right-click on the Test Plan.Click “Add > Threads(Users) > Thread group” .
Step 6: Setup Thread Group
Give a name to your Thread Group and adjust “Thread Properties” as required.
Step 7 : Add JDBC Config Element for JMeter
Add JDBC Connection Configuration By following the steps : “ Add > Config Element > JDBC Connection Configuration “
Step 8: Setup database configuration
You have to fill the Database Connection Configurations as below. The Database URL will be the location of your created database. I have used db4free.net to create the SQL database. Select MySQL driver class for JDBC Driver Class. Enter the username and password of the database in the Username and Password fields. Give the variable name as “testdb” for the created pool field.
The jdbc:mysql://[host1][:port1][,[host2][:port2]]...[/[database]] is the common format for giving your database URL. jdbc:mysql:// “ is an unchanged sequence in JMeter when specifying MySQL database address. The hostname and port name will be emailed after you create the database with db4free.net.
Step 9: Add JDBC Request Sampler in JMeter
To work with data from the database, You need to Add JDBC Request. So add JDBC Request By Clicking Add > Sampler > JDBC Request as in the image below :
Step 10: Prepare SQL query
You can type and execute the SQL query in the SQL Query section. Select all data from the table by typing the SQL below. Persons is the table name of the database. Select the Query Type as “Select Statement”.
Select * from persons;
Step 11: Update JDBC connection name
Refer the request to JDBC Connection Configuration and give the same variable name in JDBC Connection Configuration variable name field.
Step 12: Add ‘Results in Table’ listner to script
Add “ View Results in Table” listener. Right-clicking on the database name and click Add > Listener > View Results in Listener.
Step 13: Add ‘View Results Tree’ Listner
Add “View Results Tree” listener. Right-clicking on the database name and click Add > Listener > View Results Tree.
Step 14: Run your jmeter script
Test your database performance by clicking the Run button on the menu bar.
Step 15: View Results Table and Tree
You can observe your results from “View Results in Table” and “View Results Tree” Listeners
If the connection is successful, the sampler result will be given as “OK” for the “Response Message”. Check it out with your connection. You can see that the Latency of my connection is pretty high here. This is the way of checking the performance of a database with JMeter and you can get useful insights to optimize your database connection from it.