The mysql version of the pringmvc project is switched from 5.7 to 8.0

**

1. Replace the jar package:

mysql-connector-java-5.0.5.jar replaced by mysql-connector-java-8.0.11.jar
download mysql-connector-java-8.0.11.jar address

2. Modify the driver configuration jdbc.properies file

Change com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver

3. Modify the connection address:

jdbc.url=jdbc:mysql://192.168.1.245:3306/procuratorate?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&useOldAliasMetadataBehavior=true**

①Add userSSL=false
to report an error: (The main reason for reporting this warning is that the version of JDBC is not compatible with the version of MySQL, and MySQL needs to specify whether to perform SSL connection in higher versions)

Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

Translation: Establishing an SSL connection without server authentication is not recommended. According to the requirements of MySQL5.5.45+, 5.6.26+ and 5.7.6+, if no explicit option is set, an SSL connection must be established by default. To comply with existing applications that do not use SSL, the verifyServerCertificate property is set to 'false'. You need to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide a trust store for server certificate verification.

② Add serverTimezone=UTC, and modify mysql> set global time_zone='+8:00'; mysql> flush privileges;
error:

java.sql.SQLException: 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.

Translation: The server time zone value '�й���׼ʱ��' does not recognize or represent multiple time zones. If you want to take advantage of time zone support, you must configure the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specific time zone value.
Solution to this problem:

  • To temporarily take effect without restarting the mysql service, you can set
    mysql> show variables like '%time_zone%';
    mysql> set global time_zone='+8:00';
    mysql> flush privileges;
    insert image description here

Error:

Caused by:com.mysql.cj.exceptions.InvalidConnectionAttributeException: Theserver 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

Translation: com.mysql.cj exception, InvalidConnectionAttributeException service timezone value 'Öйú±ê׼ʱ¼ä', If you want to take advantage of timezone support, you must configure the server or JDBC driver (via the 'serverTimezone' configuration property) to use a more specific time zone value.
This problem is a time zone problem, just add serverTimezone=UTC to the JDBC connection url part.

③Add allowPublicKeyRetrieval=true
to report an error:

java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowe

④Add useOldAliasMetadataBehavior=true
to report an error:

column “username” not found

However, there is no such problem when executing statements on the database client.
The reason is that Java cannot use the MySQL alias (as xxx) to obtain columns. You need to add useOldAliasMetadataBehavior=true to the connection pool configuration url

**

4. Modify the mysql configuration file mysql.ini

**
error:

Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column ‘procuratorate.case_management.accepted_date’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

To put it simply: the output result is called target list, which is the field followed by select, and there is a group by column, which is the field followed by group by. Since the ONLY_FULL_GROUP_BY setting is enabled, if a field does not appear in the target list and group by fields at the same time, or is the value of the aggregation function, then this sql query is considered illegal by mysql and an error will be reported.

Solution:
1) You can take a temporary solution, but this error will still be reported after restarting mysql.
Query model: SELECT @@GLOBAL.sql_mode; SELECT @@SESSION.sql_mode;
insert image description here
you can see that the configuration of mysql contains sql_mode="ONLY_FULL_GROUP_BY"

Next, execute the following 4 SQL statements to solve the problem ( restarting mysql will fail ):

set sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
 
set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
 
set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
 
set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

2) The final solution: Modify the MySQL configuration file.
Open the my.ini file under Windows and add the following files. Be careful not to add them at the end, as they will not take effect . It is best to add them under [mysqld]:

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

Guess you like

Origin blog.csdn.net/weixin_42915457/article/details/131561075