官网下载mysql8的安装包:
https://dev.mysql.com/downloads/
下一步安装即可。
mysql8增加了传说中的安全性校验
遇到的几个问题:
1、natcat连接不上。参考链接:https://blog.youkuaiyun.com/weixin_42181147/article/details/80360151
必须执行下面两个步骤,缺一不可。
一、 mysql8.0加密方式与mysql5几加密方式不同,需要先更改加密方式。
1. 更改加密方式
ALTERUSER 'root'@'localhost' IDENTIFIED BY 'password' [a1] PASSWORDEXPIRE NEVER;
2. 更改密码
ALTERUSER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';[a2]
[a1]你的root用户密码
[a2]你的root用户密码
二、 修改root权限。可解决navicat连接mysql时报1130错误。
1.修改user表中root的权限:Update user set host = ‘%’ whereuser = ‘root’;
2.在查看user表:select user,host from user;
3.更新表:flushprivileges;
也可以在mysql安装的时候安全性选择上选mysql5的特征
然后idea配置mybatis-generator的配置
发现mysql8的驱动改了,变为:
com.mysql.cj.jdbc.Driver 执行报错,什么ssl链接方式的警告,解决方式:
jdbc:mysql://localhost:3306/testweb?useSSL=false
加参数指定一下。 然后有报时区不一致啥问题。参考链接:https://blog.youkuaiyun.com/weixin_41908757/article/details/80283015
1、错误原因: 使用原mysql5.1.38不会出现该问题 因使用了Mysql最新版驱动所以报错 2、解决方案: 方案1、在项目代码-数据库连接URL后,加上 (注意大小写必须一致) ?serverTimezone=UTC 方案2、在mysql中设置时区,默认为SYSTEM set global time_zone='+8:00'
Sun Mar 19 20:51:50 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended.
According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option
isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'.
You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server
certificate verification.
从警告信息中可以看出,5.5.45+、5.6.26+ 和 5.7.6+ 版本默认 SSL 连接,除非特别指定不需要 SSL 连接,最好在 JDBC URL 中指明连接方式:
String jdbcUrl = "jdbc:mysql:///test?useSSL=false";
首先,我居然不能用navicat客户端连接上mysql8.0数据库报1251错误,这个的解决方式已经在我的上一篇博客中解决了。然后我又遇到了java无法连接mysql数据库8.0的问题。
报错:Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Wed May 09 16:25:23 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
上面这段报错中加粗的文字很重要,她告诉你mysql8.0和之前版本的区别,首先驱动换了,不是com.mysql.jdbc.Driver而是'com.mysql.cj.jdbc.Driver',此外mysql8.0是不需要建立ssl连接的,你需要显示关闭。最后你需要设置CST。所以我们需要在之前我们熟悉的java连接数据库代码的基础之上改动以下两行代码:
- Class.forName("com.mysql.cj.jdbc.Driver");
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_demo?useSSL=false&serverTimezone=UTC","root","password");
- conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_demo","root","password");
注意:
- Class.forName("com.mysql.cj.jdbc.Driver");