Building MySql Database Test Plan Using Jmeter

23 / Apr / 2015 by Prashant Sharma 1 comments

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

  1. Thread group named ‘MySql Database’ : Select Add > Threads (Users) > Thread Group.
  2. Sampler of type JDBC Request : Select Add > Sampler > JDBC Request 
  3. Add the following value in JDBC Request:
    • Name : Query
    • Enter the Pool Name : Test
    • Query Type : Select statement
    • Enter the SQL Query String field
  4. JDBC Request configuration can seen in screen shotSelect
  5. Config element of type JDBC Connection Configuration : Select Add > Config Element > JDBC Connection Configuration
  6. 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
  7. JDBC Connection Configuration can seen in screen shot.
    Jmeter_config
  8. 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

jmeter_2

 

Thanks
Prashant Sharma
FOUND THIS USEFUL? SHARE IT

comments (1 “Building MySql Database Test Plan Using Jmeter”)

  1. Vishal

    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.

    Reply

Leave a Reply to Vishal Cancel reply

Your email address will not be published. Required fields are marked *