The database in the Java project was changed from mysql 5.7 to mysql8.0.18

After we download or purchase a project from the Internet, if we want to run it locally, the first thing we need to do is to check whether the required environment is consistent, that is, the versions of Tomcat/IDEA/JDK/Mysql must be consistent. Today, I will mainly talk about some database mismatches that I often encounter.

Some friends purchased the project in the source space station , and then found that the Mysql version required in the project was 5.7, but the Mysql version installed locally was 8.0, so what should we do?

Two options:

  1. Install Mysql 5.7 locally;
  2. Modify the configuration file and driver jar package in the project, and change the Mysql version from 5.7 to 8.0;

The first method, I won't go into too much detail here, you can download the installation package and install it directly. The original version of the database can be uninstalled or not. If you do not uninstall, you must pay attention to setting different port numbers to prevent port conflicts;

Here we introduce the second method in detail, how to modify the configuration file and driver jar package in the project.

1. Changes to the driver jar package

If it is a non-Maven project, first modify the driver jar package in the lib library, MySQL 8.0 or above driver package version mysql-connector-java-8.X.jar, the driver package can be downloaded from the Internet;

Note: Be sure to use the driver package of mysql-connector-java-8.X.jar and above

2. Change of driver name

Before version 5.0, it was com.mysql.jdbc.Driver.
In 8.0, you need to add cj, that is, com.mysql.cj.jdbc.Driver

3. Change of url

In the past, only jdbc:mysql://localhost:3306/datasource database name
was needed. After the version is changed, you need to add encoding SSL and time zone like this.
url=jdbc:mysql://localhost:3306/bookms3? useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone= UTC

4. Projects using maven architecture must first modify the pom file

1. Before version 5.0

<dependency>	<groupId>mysql</groupId>	<artifactId>mysql-connector-java</artifactId>	<version>5.1.38</version></dependency>

2. After version 8.0

<dependency>   <groupId>mysql</groupId>   <artifactId>mysql-connector-java</artifactId>   <version>8.0.18</version></dependency>

3. You can use database connection tools such as Navicat to create a new query statement in the database and query the mysql version


After the above steps are completed, it can be successful under normal circumstances. If not, you can contact the source code space station customer service staff to make changes.