Building MySql Database Test Plan Using Jmeter
In this blog we will setup the jmeter and we will see how to create a simple test plan to test the database server.We will use MySql database server for our test purpose or you can use any-other database.
Setup requirement
- Download the latest jmeter from here and untar jmeter in you home directory.
- Download JDBC driver is needed in JMeter for connection with MySQL database. You can download MySQL JDBC driver from here.
- Copy the driver JAR file in JMeter installation’s lib folder. Restart JMeter if it is already open.
- Install the mysql on you machine.
- Once MYSQL is installed, follow the steps below to setup the database
- Create a database with name “loadtesting”.
- Create a table loadtesting.
- Insert records into loadtesting
[js]
mysql> use loadtesting;
Database changed
mysql> INSERT INTO loadtesting
-> (customer_id,order_id,result) VALUES
-> (2,1,1);
Query OK, 1 row affected (0.04 sec)
mysql> INSERT INTO loadtesting
-> (customer_id,order_id,result) VALUES
-> (1,1,1);
Query OK, 1 row affected (0.04 sec)
[/js]
Create Test Plan
let’s start the JMeter from /home/prashants/jmerter/apache-jmeter-2.13/bin/jmeter.sh
Add the following components in the Test plan
- Thread group named ‘MySql Database’ : Select Add > Threads (Users) > Thread Group.
- Sampler of type JDBC Request : Select Add > Sampler > JDBC Request
- Add the following value in JDBC Request:
- Name : Query
- Enter the Pool Name : Test
- Query Type : Select statement
- Enter the SQL Query String field
- JDBC Request configuration can seen in screen shot
- Config element of type JDBC Connection Configuration : Select Add > Config Element > JDBC Connection Configuration
- Add the following value in JDBC Connection Configuration:
- Variable Name : Variable name bound to pool. This needs to identify the configuration uniquely. It is used by the JDBC Sampler to identify the configuration to be used. We have named it as test.
- Database URL: jdbc:mysql://localhost:3306/loadtesting
- JDBC Driver class: com.mysql.jdbc.Driver.
- Username: root
- Password: root
- JDBC Connection Configuration can seen in screen shot.
- Listener type: select Add > Listener > View Results Tree.
Save and Run Test Plan
Save the test as mydatabase.jmx and execute this test plan using Run > Start option.
Output
Thanks Prashant Sharma
Thanks for the wonderful article.
I was wondering if there is any way through which we can connect two separate JDBC connections (say DB1 and DB2) under same Test plan. may be in same or different Thread groups.
Any thoughts on this.