連接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;替代;。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章