mysql-8.0.12 Could not create connection to database server - java mysql connector

Could not create connection to database server - java mysql connector

一、mysql授权

此前参考https://blog.csdn.net/xinpengfei521/article/details/80403965设置报:

java报错: null,  message from server: "Host 'windows10.microdone.cn' is not allowed to connect to this MySQL server"

数据库报错: You are not allowed to create a user with GRANT

解决方法:

在mysql的bin目录下执行:mysql -u root -p密码 登陆到数据:
执行use mysql;

执行:update user set host=’%’ where user =’root’;

执行刷新权限:flush privileges;

可以测试外网连接mysql服务器。

参考:https://blog.csdn.net/vincent0012/article/details/80743259解决

二、(Mysql8.0)Could not create connection to database server - java mysql connector

问题:我用的mybatis的驱动包(mysql-connector-java-5.1.38-bin)与8.0不符合
最后我把驱动包改为 mysql-connector-java-8.0.11(点击下载)密码为 igvz 的

最后记得把jdbc.properties的配置改变一下:driver=com.mysql.cj.jdbc.Driver

再重新开启服务器就发现可以连接到数据库了

补充:

可能会遇到接下来的问题 :java.sql.SQLException: The server time zone value(MyBatis时区错误)

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.

url=jdbc:mysql://localhost:3306/person?serverTimezone=UTC&characterEncoding\=utf-8

就在url上面添加上 serverTimezone=UTC 就可以了

参考:https://blog.csdn.net/ccczequn/article/details/81260833

之前还出现修改密码报错

参考博客地址:https://www.cnblogs.com/reyinever/p/8551977.html
但其中开启远程访问报错、可参考我上面说的

也许mysql-8.0.12设置密码和之前不一样吧
问题解决:

use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '111111';
FLUSH PRIVILEGES;

这期间还涉及MySQL的密码认证插件是mysql_native_password,而现在使用的是caching_sha2_password。

因为当前有很多数据库工具和链接包都不支持caching_sha2_password,为了方便,我暂时还是改回了mysql_native_password认证插件。

在MySQL中执行命令:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

此次尝试新版本感觉累觉不爱、之前找一个my.ini文件找了半天找不到、还有人说在c盘的一个隐藏文件下、我也去找了找了之后我想想这个是解压的、不可能去哪里。最后又有人说新建一个,新建之后启动都启动不起来了,不过还是成功解决了

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值