记录mysql8.0遇到的bug
MySql链接报错
新安装的mysql8.0.22 明明前两天测试能通过连接,但是在cmd运行 mysql -u root -p时,输入密码后总会报错。显示如下:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
通过搜索了大量的文章后成功解决,记录一下解决方法。
第一步:到开始搜索框搜索cmd,用管理员身份运行,然后输入 net stop mysql 关闭Mysql服务。
第二步:进入到安装Mysql的bin目录中执行 :mysqld --console --skip-grant-tables --shared-memory,此时输出有这些后,该cmd窗口不要关闭,重新再开一个cmd窗口
第三步:在新的cmd窗口中,执行 mysql -uroot -p 就能不用密码进入。
第四步:此时就能修改密码了,按顺序执行命令就可以完成修改密码。
1、use mysql
2、update user set authentication_string='' where user='root' ;
3、flush privileges; 刷新权限表
4、ALTER user 'root'@'localhost' IDENTIFIED BY 'root'; 修改root密码
这样已经成功解决问题了。
Springboot链接Mysql8.0出错
报错代码
pring boot 启动时,连接mysql 8.0.22数据库报错 errorCode 0, state 08001。
springboot项目中的pom文件中配置的Mysql驱动版本与mysql数据库版一致
修改pom文件中的版本即可,可以使用下面的配置:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
</dependency>
yml中的配置应该改为:
driver-class-name: com.mysql.cj.jdbc.Driver
链接参数修改为:
url: jdbc:mysql://localhost:3306/数据库名称?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Hongkong
这样后就成功了。
application.yml
随便记录下信息。。
spring:
datasource:
url: jdbc:mysql://localhost:3306/数据库名称?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Hongkong
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
type: com.alibaba.druid.pool.DruidDataSource
initialSize: 5
minIdle: 5
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
filters: stat,wall,log4j
maxPoolPreparedStatementPerConnectionSize: 200
useGlobalDataSourceStat: true
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500