2

How to connect with My Sql database without using JDBC Connection Configuration and JDBC Samplers?

I want to establish connection with My SQL database without using JDBC Connection Configuration and JDBC Samplers as I don't want to keep the database credentials in .JMX file for security reasons.

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
Nahor
  • 83
  • 1
  • 7

2 Answers2

0

You don't need to put password (/user) inside jmx file, you can load values using property

For example use __property to get value from property instead of hardcoded value:

${__property(password)}

The property function returns the value of a JMeter property

properties can be set adding to properties file or command line parameter

Java system properties and JMeter properties can be overridden directly on the command line (instead of modifying jmeter.properties).

-J[prop_name]=[value] defines a local JMeter property.

Community
  • 1
  • 1
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
0

If you don't want to use JDBC test elements for building a database test plan you can always switch to JSR223 Test Elements and program whatever you want using Groovy language, in your case your friend is groovy.sql.Sql

Example code:

def dburl = 'jdbc:mysql://192.168.99.100:3306/mysql'
def user = 'root'
def password = props.get('db.password')
def driver = 'com.mysql.cj.jdbc.Driver'
groovy.sql.Sql.withInstance(dburl, user, password, driver) { sql ->
    sql.query('select name,url from help_topic order by rand() limit 2;') { resultSet ->
        while (resultSet.next()) {
            def name = resultSet.getString(1)
            def url = resultSet.getString('url')
            log.info('Topic name: ' + name + ' topic url: ' + url)
        }
    }
}

Example output:

enter image description here

This line: props.get('db.password') is reading the value from JMeter Properties, you can set the property value using -J command-line argument like:

jmeter -Jdb.password=secret -n -t test.jmx -l result.jtl

Check out Apache Groovy - Why and How You Should Use It article for more information on Groovy scripting in Jmeter


You will still need to have MySQL Connector/J in JMeter Classpath

Dmitri T
  • 159,985
  • 5
  • 83
  • 133