MySQL 8.0版本連線報錯:Could not create co
準備搭建一個Spring Boot 組合mybatis的專案,資料庫採用的是MySQL 8.0.11按照以往的配置,使用外掛mybatis-generator-maven-plugin生成程式碼時,一直報錯Could not create connection to database server.如下:
[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------[INFO] Building songci-serv 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------[INFO] [INFO] --- mybatis-generator-maven-plugin:1.3.5:generate (default-cli) @ songci-serv ---[INFO] Connecting to the Database [INFO] ------------------------------------------------------------------------[INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------[INFO] Total time: 1.841 s [INFO] Finished at: 2018-08-22T21:32:27+08:00[INFO] Final Memory: 13M/46M [INFO] ------------------------------------------------------------------------[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.5:generate (default-cli) on project songci-serv: Could not create connection to database server. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
經排查是,MySQL8.0版本需要更換驅動為“com.mysql.cj.jdbc.Driver”,之前的“com.mysql.jdbc.Driver”已經不能在MySQL 8.0版本使用了,官方文件連結:https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-api-changes.html;
描述如下:The name of the class that implements java.sql.Driver in MySQL Connector/J has changed from com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver. The old class name has been deprecated.
另外mysql-connector-java也推薦更新到8.0的版本(https://dev.mysql.com/downloads/connector/j/)。
綜上修改以下兩點:
1.更新mysql-connector-java版本:
<!-- --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.11</version></dependency>
2.更換驅動:
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/test? useUnicode=true&characterEncoding=utf-8&useSSL=false" userId="root" password="root"/>
配置好以上兩點,執行mybatis-generator-maven-plugin,接著報錯如下:
Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.5:generate (default-cli) on project songci-serv: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
報時區錯誤,解決方法執行命令給MySQL伺服器設定時區為東八區,這個是com.mysql.cj.jdbc.Driver需要指定的:
mysql> set global time_zone='+8:00';
Query OK, 0 rows affected
Navicat中命令列介面執行即可。或者在資料庫連線配置中加上serverTimezone=GMT%2B8(代表東八區),如下:
connectionURL="jdbc:mysql://127.0.0.1:3306/songci?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8"
作者:
原文連結:https://www.cnblogs.com/smiler/p/9963773.html
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/2157/viewspace-2820372/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- pg_basebackup 報錯could not create directory
- Java專案連線資料庫Mysql報錯create connection SQLExceptionJava資料庫MySqlException
- SQLyog連線MySQL8.0報2058錯誤的完美解決方法MySql
- Mysql8.0 報錯MySql
- Linux下ODBC連線HGDB報Could not SQLConnect錯解決方法LinuxSQL
- mysql 8.0 使用 navicat 登入報錯MySql
- Navicat連線centos裡mysql報錯Host is not allowed to connect to this MySQL serverCentOSMySqlServer
- mysql連線錯誤(2013)MySql
- su - xxx Could not create sessionSession
- SQLyog連線資料庫報錯:錯誤號碼2058 plugin caching_sha2_password could not be loadedSQL資料庫Plugin
- MySQL 本地連線遠端伺服器報錯 2003MySql伺服器
- 連線mysql報錯lost connect to sever during query解決MySql
- 遠端連線MySQL錯誤“plugin caching_sha2_password could not be loaded”的解決辦法MySqlPlugin
- mysql連線錯誤碼1251MySql
- mysql8.0 部分sql語法報錯問題MySql
- Arcgis連線HGDB報錯
- DBeaver連線MySQ報錯
- JDBC連線mysql-8.0實現增刪改查JDBCMySql
- C#連線MySQL8.0資料庫失敗C#MySql資料庫
- Percona Toolkit工具連線MySQL 8報錯的解決方案MySql
- 連線zk 報錯連線不上hbase jdbcJDBC
- 連線MYSQL 錯誤程式碼2003MySql
- navicat連線MySQL8.0.11報2059錯誤的解決方案MySql
- MySQL 8.0之後版本密碼修改MySql密碼
- navicat連線遠端伺服器docker的mysql容器時連不上報錯伺服器DockerMySql
- 虛擬機器NAT模式下連線mysql報錯:Host '192.168.30.1' is not allowed to connect to this MySQL server虛擬機模式MySqlServer
- 【MySQL】Novicat 連線mysql 報錯1251的問題處理,Novicat12 破解方法MySql
- 連線 MySQL 8.0 時,加密方式不相容的解決方法MySql加密
- OGG Director連線報錯Access denied
- 低版本客戶端連線高版本資料庫報錯ORA-28040、ORA-01017客戶端資料庫
- MySQL 8.x 新版本JDBC連線方式MySqlJDBC
- Mysql連線錯誤ERROR 2003 (HY000)MySqlError
- sshd啟動報錯Could not load host key
- 騰訊雲資料庫 MySQL 8.0 正式上線,效能全面超越官方版本資料庫MySql
- Mysql出現連線錯誤解決辦法MySql
- MySQL建立使用者報錯 ERROR 1396 (HY000): Operation CREATE USER failed for 'afei'@'%'MySqlErrorAI
- SQLYOG連線資料庫時報錯1251SQL資料庫
- cmake報錯CMake Error: Could not find CMAKE_ROOTError