连接Mysql5.7时候遇见的一些奇葩的问题

前言:我就没遇见这么有脾气的数据款,一个连接字符串这么我老久了,每种配置文件都特么不一样,记录下,下次好过坑

        

问题一、提示你需要指定SSL连接

<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/mybatis" 
			userId="root"
			password="123456">
	</jdbcConnection>

警告信息:

EstablishingSSL connection without server's identity verification is notrecommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+requirements SSL connection must be established by default ifexplicit option isn't set. For compliance with existing applicationsnot using SSL the verifyServerCertificate property is set to 'false'.You need either to explicitly disable SSL by setting useSSL=false, orset useSSL=true and provide truststore for server certificateverification.

        按这个提示应该是说SSL需要指定:指定好了,可以解决,但是如果搭上指定字符集又遇上问题了

问题二:指定SSL连接后,指定字符集

<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/mybatis?useSSL=false;characterEncoding=utf-8" 
			userId="root"
			password="123456">
	</jdbcConnection>

警告信息:

java.sql.SQLException:The connection property 'useSSL' only accepts values of the form:'true', 'false', 'yes' or 'no'. The value'false;characterEncoding=utf-8' is not in this set.

 

        我最开始是觉得是不是逗号写错了,后来发现没问题,综合网上的将“;”换成了&&ampxml校验不通过,发现在db.properties中可以使用&进行连接,如果是在value或者xmlproperty中进行拼接则校验不通过。

        最好解决方案:

<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/mybatis?useSSL=false&characterEncoding=utf-8" 
			userId="root"
			password="123456">
	</jdbcConnection>
最终的方案:

1、如果是在properties文件中,可以使用&进行属性的分割。

2xml的字符串中进行拼接,他总会提示你用;替换&符号,但是有的可以有的又不行,必须mybatis单独使用的时候在value属性里面指定连接字符串的时候可以用;就可以了,但是在mybatis的逆向工程中,指定的话就会报错。所以综合下,在xml中使用jdbc:mysql://localhost:3306/mybatis?usessl=true&amp;characterEncoding=utf-8中的&amp;替代;。


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
通过分析引用内容,可以得出以下结论: 需要使用Spring Boot连接MySQL 5.7时,可以按照以下步骤进行配置: 1. 在application.properties文件中配置MySQL主库的连接信息。在该文件中,可以找到以下配置项: - spring.datasource.master.driver-class-name:指定MySQL主库的驱动类。 - spring.datasource.master.jdbcUrl:指定MySQL主库的连接URL。 - spring.datasource.master.username:指定连接MySQL主库的用户名。 - spring.datasource.master.password:指定连接MySQL主库的密码。 2. 在application.properties文件中配置MySQL从库的连接信息。在该文件中,可以找到以下配置项: - spring.datasource.slave.driver-class-name:指定MySQL从库的驱动类。 - spring.datasource.slave.jdbcUrl:指定MySQL从库的连接URL。 - spring.datasource.slave.username:指定连接MySQL从库的用户名。 - spring.datasource.slave.password:指定连接MySQL从库的密码。 请根据实际情况将以上配置项中的占位符替换为正确的值,并确保MySQL主库和从库的连接信息正确无误。这样就可以使用Spring Boot连接MySQL 5.7了。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [SpringBoot 读写分离(配Mysql5.7) 笔记](https://blog.csdn.net/wangdonghao137/article/details/127805751)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值