【JMeter】JMeter连接Mysql8.x数据库的坑

1,系统管理员打开CMD,进入D:\Program Files\apache-jmeter-5.4.3\bin 启动 Jmeter

--mysql版本与jar包版本对应,否则可能某网站给jar包都要收费也是醉醉,官网可以直接拿

下载Mysql网址:https://dev.mysql.com/downloads/mysql/

mysql官网下载对应jar包网址:https://downloads.mysql.com/archives/c-j/

或者这里下载对应的jar包:

https://mvnrepository.com/,搜索MySQL Connector/J,选择对应的版本。

2,测试计划配置

 3,添加线程组,再添加JDBC Connection Configuration

4,添加请求

5,添加监听器看结果

 

6,记录踩坑之路……

1)Cannot create JDBC driver of class '' for connect URL 'jdbc:mysql://localhost:3306/test'

——解决:mysql版本与jar版本要一致,导入jar包,连接数据库写法正确,8.x记得手写上面指定位置的内容

select version();   //查看mysql版本
show global variables like 'port';  //查看mysql的端口

2)Host is not allowed to connect to this MySQL server

——解决:开启远程访问并修改密码(基于mysql8.x)

至于mysql密码的修改,移步至:https://www.cnblogs.com/pearl07/p/16199428.html

 

以下转自博客园博主@厸厸 ,可移步: https://www.cnblogs.com/nimeide/p/14802113.html

windows环境中 在安装mysql或者启动不了mysql服务时,切记

右击此电脑–>管理–>本地用户和组–>组–>双击Administrators–>添加–>高级
把NETWORK SERVICE添加到Administrators组

 

C:\Users\Administrator>mysql -u root -P 3306 -p    指定端口账号登录
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.25 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql
Database changed
mysql> select User,Password,Host from user;
ERROR 1054 (42S22): Unknown column 'Password' in 'field list'
mysql> select User,Host from user; //查看用户数据
+------------------+-----------+
| User | Host |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'root' with grant option' at line 1
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> grant all privileges on *.* to root@'%' identified by "Sz321654"; //8.x以前版本写法
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by "Sz321654"' at line 1
mysql> update user set host='%' where user='root'; //先修改user表中的root的host字段数据
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

mysql> grant all on *.* to 'root'@'%'; //给root用户权限
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql> flush privileges;//刷新权限缓存
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';//修改为mysql_native_password访问方式 因为在native访问的加密方式不一样

Query OK, 0 rows affected (0.00 sec)

mysql> select host,user,plugin from mysql.user;//查看修改之后
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)

mysql> alter user 'root'@'%' identified with mysql_native_password by '你的密码';
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)

mysql>

 

posted @ 2022-04-27 22:00  pearl007  阅读(396)  评论(0编辑  收藏  举报