1. 程式人生 > 實用技巧 >### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

最近在學mybatis~遇上了第一個坑【難受啊哈,感覺有必要講一下】
按理說在資料庫連線的url對應的值中useSSL=true&useUnicode=true表示的是安全連線為true,看上去貌似沒有毛病【也是因為一直覺得沒毛病,才導致我排錯排了好久都沒察覺它的問題】
【說明一下】我用的是5.7的MySQL,2018版本的idea。想連線idea自帶的MySQL資料庫,連是連上了,不過報了個錯(忘記具體的錯叫什麼了),這也導致我後面的程式執行不起來,報### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure。
網上各種方法都試了還是沒有起效。後來試著把useSSL=true&useUnicode=true

的值改成false,結果錯誤都解決了【but,我不知道這是為什麼】
【好像羅裡吧嗦講得亂了些,各位道友海涵~】

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">

<!--configuration:核心配置檔案-->
<configuration>
    <!--environments 表示一套環境配置,可以配置多套環境,如果需要的話-->
    <environments default="development">
        <environment id="development">
            <!--transactionManager表示事務管理,預設是JDBC方式-->
            <transactionManager type="JDBC"/>
            <!--資料庫連線的資訊-->
            <dataSource type="POOLED">
                <!--mysql驅動-->
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=true&amp;useUnicode=true&amp;characterEncoding=UTF-8"/>
                <property name="username" value="你的資料庫使用者名稱"/>
                <property name="password" value="資料庫密碼"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>
        <mapper resource="com/lobster/dao/UserMapper.xml"></mapper>
    </mappers>
</configuration>