安装连接mysql8时候遇到的问题以及解决(转)

本文详细介绍了MySQL 8.0在安装及使用过程中遇到的常见连接问题,包括Navicat客户端连接失败、Java应用连接失败等,并提供了具体的解决方法,如更改加密方式、设置SSL连接参数等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

官网下载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连接数据库代码的基础之上改动以下两行代码:

[java]  view plain  copy
  1. Class.forName("com.mysql.cj.jdbc.Driver");  
  2. Class.forName("com.mysql.jdbc.Driver");  
  3. conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_demo?useSSL=false&serverTimezone=UTC","root","password");  
  4.   conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_demo","root","password");  
改动完了之后你就可以成功连上mysql数据库数据库8.0了。


注意:

  1. Class.forName("com.mysql.cj.jdbc.Driver");  
驱动jar包用最新的才能使用连接池。

















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值