1. 下載 mysql-connector-java-8.0.11.jar
版本參考:https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-versions.html
下載地址:https://repo1.maven.org/maven2/mysql/mysql-connector-java/
2. 添加數據庫jar包
拷貝mysql驅動包到jmeter/lib目錄下
或者
在測試計劃處添加驅動jar包

image.png
3. 添加一個線程組以及JDBC Request

image.png
4. 添加JDBC Connection Configuration

image.png
Variable Name for created pool:自定義連接池名稱
Database URL:jdbc:mysql://{ip}:{port}/{dbname}?useUnicode=true&characterEncoding=utf8
JDBC driver class:JDBC驅動
Username:數據庫用戶名
Password:數據庫密碼
| Datebase | Driver class | Database URL |
|---|---|---|
| MySQL | com.mysql.jdbc.Driver | jdbc:mysql://host:port/{dbname} |
| PostgreSQL | org.postgresql.Driver | jdbc:postgresql:{dbname} |
| Oracle | oracle.jdbc.driver.OracleDriver | jdbc:oracle:thin:user/pass@//host:port/service |
| Ingres (2006) | ingres.jdbc.IngresDriver | jdbc:ingres://host:port/db[;attr=value] |
| MSSQL | com.microsoft.sqlserver.jdbc.SQLServerDriver或者net.sourceforge.jtds.jdbc.Driver | jdbc:sqlserver://IP:1433;databaseName=DBname或者jdbc:jtds:sqlserver://localhost:1433/"+"library" |

image.png
如果遇到如下報錯:
Cannot create PoolableConnectionFactory (The server time zone value '?????????????????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.)在Database URL 中添加
serverTimezone=UTC
image.png

image.png

image.png