How To Do Database Testing with JMeter

Create a basic JMeter database test script against MySQL Database

Table of Contents

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.

1
Step 1: Launch Jmeter.

blank

You can run JMeter using the “ApacheJMeter.jar” file which is in the “bin” folder. Here is a screenshot of JMeter GUI :

2
Step 2: Download MySQL Connector

blank

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 :

3
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.

4
Step 4: Now Restart JMeter

Restart the JMeter so that it will work with the library provided by MySQL connector.

5
Step 5 : Create JMeter Thread Group

blank

Right-click on the Test Plan.Click “Add > Threads(Users) > Thread group” .

6
Step 6: Setup Thread Group

blank

Give a name to your Thread Group and adjust “Thread Properties” as required.

7
Step 7 : Add JDBC Config Element for JMeter

blank

Add JDBC Connection Configuration By following the steps : “ Add  > Config Element > JDBC Connection Configuration “

8
Step 8: Setup database configuration

blank

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.
blank

9
Step 9: Add JDBC Request Sampler in JMeter

blank

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 :

10
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;

11
Step 11: Update JDBC connection name

blank

Refer the request to JDBC Connection Configuration and give the same variable name in JDBC Connection Configuration variable name field.

12
Step 12: Add ‘Results in Table’ listner to script

blank

Add “ View Results in Table”  listener. Right-clicking on the database name and click Add > Listener > View Results in Listener.

13
Step 13: Add ‘View Results Tree’ Listner

blank

Add “View Results Tree” listener. Right-clicking on the database name and click Add > Listener > View Results Tree.

14
Step 14: Run your jmeter script

blank

Test your database performance by clicking the Run button on the menu bar.

15
Step 15: View Results Table and Tree

blank

You can observe your results from “View Results in Table” and “View Results Tree” Listeners

blank
blank

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.

Tushar Sharma
Tushar Sharmahttps://www.automationdojos.com
Hi! This is Tushar, the author of 'Automation Dojos'. A passionate IT professional with a big appetite for learning, I enjoy technical content creation and curation. Hope you are having a good time! Don't forget to subscribe and stay in touch. Wishing you happy learning!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

RELATED POSTS

How To Do API Testing with JMeter

Introduction Application Programming Interface is a very popular term among developers. It is simply a request provider that responds to your request. In other words,...

Working with JMeter Listeners

About Listeners Listeners are used for displaying test results in JMeter. Listeners allow system engineers to analyze the responses from the testing system and monetize...

Getting Started with Apache JMeter

1. Introduction As a developer, you may have tested the functionality of your code hundreds of times during development. This is known as functional testing....

How To Record Using BlazeMeter Plugin (JMeter)

Honestly speaking if you already have a mature or established process using 'native' JMeter from Apache, without any kind of wrappers utilities or third-party...

Â

RECENT 'HOW-TO'

How To Install Oh-My-Posh On Windows PowerShell

Oh-My-Posh is a powerful custom prompt engine for any shell that has the ability to adjust the prompt string with a function or variable. It does not...

MORE ON CODEX

FEATURED PROJECTS

Windows JDK Manager (win-jdk-Manager)

ADjo LABS PROJECT : Simple and lightweight desktop utility with Interactive cmd Interface for easy view, re-point and switching between JAVA versions on windows. Demonstrating the capability...

MORE IN THIS CATEGORY

Essentials of Typical QTP/UFT Framework

Table of Contents Essentials 1: Test Artefacts Repository Essentials 2: Error Handling and Recovery Essentials 3: Object Identification Method Essentials 4: Test Data Management Essentials 5: Result and...

How To Create Dashboards with Jira

What is a Jira Dashboard? The Jira dashboard is like a control panel for your projects. You can create several dashboards for each project you...

Common Errors with QTP/UFT – Part 1

As the name suggests, this article focuses on the common problems faced during or after QTP/UFT installation. We shall also have a separate article...

How to View Java API Doc Hints within IntelliJ

IntelliJ Quick Documentation So how do you generally refer your Java API Doc? If you use Google or online Java API Doc or even a...

CHECKOUT TUTORIALS

VBS Part 1 – Introduction and Background

At the upfront, this theoretical article might look boring to most of us but still, it is advisable to know about our scripting friend...

Working with JMeter Listeners

- Advertisement -spot_img