Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jmeter JDBC Connection Configuration Parametrization of Database URL for accessing MySQL Database

How to parametrize Database URL under JDBC Connection Configuration? Normal parametrization is not working here.

This doesn't work:

Database URL: jdbc:mysql://${mysql_hostname}:${mysql_port}/${mysql_database}
JDBC Driver Class: com.mysql.jdbc.Driver
Username: ${mysql_username}
Password: ${mysql_username}
like image 958
Nelly Avatar asked Jun 15 '17 19:06

Nelly


People also ask

What is JDBC connection configuration JMeter?

The JDBC Connection Configuration is used to configure JMeter connections to the database. 5. Fill in the Variable Name field. The value of this field is used to associate a specific connection configuration (JDBC Connection Configuration) to the database and a specific request (JDBC Request) sent by JMeter.

Can JMeter connect to database?

JMeter can connect to any database and run SQL queries concurrently. In order to do so, it's mandatory to have necessary JDBC drivers in the lib folder of your installation. Most important part of the Database performance testing is to have valid connection strings in JDBC Connection Configuration.

What is the correct format of JDBC URL?

protocol – jdbc:mysql: host – mysql. db. server:3306.

In which location are JDBC drivers placed in JMeter?

Run tests with just the JMeter client Copy the JDBC Driver file to /usr/local/jmeter/lib.


2 Answers

The point is that JDBC Connection Configuration test element is being initialized before JMeter Variables so if you want to parameterize it you should be doing it a little bit differently to wit:

  • Use __P() function where required like:

    Database URL: jdbc:mysql://${__P(mysql_hostname,)}:${__P(mysql_port,)}/${__P(mysql_database,)}
    JDBC Driver Class: com.mysql.jdbc.Driver
    Username: ${__P(mysql_username,)}
    Password: ${__P(mysql_password,)}
    

The relevant JMeter Properties can be set either in user.properties file like:

mysql_hostname=localhost
mysql_port=3306
mysql_database=test
mysql_username=johndoe
mysql_passowrd=secret

Or via -J command-line argument like:

jmeter -Jmysql_hostname=localhost -Jmysql_port=3306 -Jmysql_database=test -Jmysql_usename=johndoe -Jmysql_password=secret

See Apache JMeter Properties Customization Guide for more information on JMeter Properties and ways of setting and overriding them

like image 163
Dmitri T Avatar answered Oct 17 '22 15:10

Dmitri T


in Jmeter (5.1.1) you can use 'User Defined Variables'. Add-> Config Element -> User Defined Variables.

1) Provide User Defined Variables, like, db host, db port, user name, password...

2)create JDBC Connection Configuration, and use defined variables

3)do your JDBC Request

4) Check results

like image 1
Robby Avatar answered Oct 17 '22 17:10

Robby