MySQL 升级到版本 8 后 Java 应用程序面临数据库连接错误

问题描述 投票:0回答:1

我在复杂的情况下遇到了问题。我有 MySQL 5,最近将其升级到 MySQL 8。从那时起,我的 Java 应用程序最初在 Tomcat 上运行时无法正常工作。

但是更新pom.xml文件中的MySQL依赖后,问题依然存在。 来自

<dependency>
    <groupId>org.mariadb.jdbc</groupId>
    <artifactId>mariadb-java-client</artifactId>
    <version>1.7.3</version>
</dependency>

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

<dependency>
   <groupId>org.mariadb.jdbc</groupId>
   <artifactId>mariadb-java-client</artifactId>
   <version>1.8.0</version>
</dependency>
<dependency>
   <groupId>com.mysql</groupId>
   <artifactId>mysql-connector-j</artifactId>
   <version>8.0.33</version>
</dependency>

现在它可以正常工作了,但我遇到了数据库问题。我一直收到“连接过多”错误。当我执行查询 SHOW PROCESSLIST; 时,我收到以下结果: enter image description here

我的结果中有大约 200 行与此 user1 类似。并已设置

max_connexion=200
;

当我在代码库中搜索“database1”时,我发现它在 persistence.xml 文件中引用,配置如下:

<properties>
        
            <property name="hibernate.connection.driver_class" value="org.mariadb.jdbc.Driver" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="hibernate.cache.use_second_level_cache" value="true" />
            <property name="hibernate.cache.use_query_cache" value="true" />
            <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/>
            <property name="hibernate.cache.provider_class"  value="org.hibernate.cache.EhCacheProvider"  />
            <property name="hibernate.show_sql" value="false" />
            <property name="hibernate.format_sql" value="false" />
            <property name="hibernate.generate_statistics" value="true" />
            <property name="hibernate.connection.release_mode" value="auto" />
            <property name="hibernate.archive.autodetection" value="class, hbm"/>
            <property name="hibernate.bytecode.use_reflection_optimizer" value="true"/>
            <property name="hibernate.bytecode.provider" value="javassist"/>


            <!-- create database schema at startup -->
            <!-- not for real application -->
            <!-- <property name="hibernate.hbm2ddl.auto" value="create" /> -->


            <property name="connection.provider_class"  value="org.hibernate.connection.C3P0ConnectionProvider"/>
            <property name="hibernate.c3p0.min_size" value="5" />
            <property name="hibernate.c3p0.max_size" value="20" />
            <property name="hibernate.c3p0.timeout" value="3600" /> <!-- <property name="hibernate.c3p0.timeout" value="1800" /> -->
            <property name="hibernate.c3p0.idle_test_period" value="3600"/> <!-- idle_test_period < timeout -->
            <property name="hibernate.c3p0.max_statements" value="50" />
            <property name="hibernate.c3p0.preferredTestQuery" value="SELECT 1" />
            <property name="hibernate.c3p0.testConnectionOnCheckin" value="true" />
            <property name="hibernate.c3p0.testConnectionOnCheckout" value="false" /> <!-- pas recommandé : http://www.mchange.com/projects/c3p0/ --><!-- <property name="c3p0.testConnectionOnCheckout" value="true" /> -->
 
             <property name="hibernate.connection.url" value="jdbc:mysql://${serverNameBD}:${portNumberBD}/${databaseNameBD}"/>
             <property name="hibernate.connection.driver_class" value="org.mariadb.jdbc.Driver" />
             <property name="hibernate.connection.password" value="${passwordBD}" />
              <property name="hibernate.connection.username" value="${userBD}" />


            <property name="hibernate.connection.autoReconnect" value="true" />
            <property name="hibernate.connection.autoReconnectForPools" value="true" />
            <property name="hibernate.connection.is-connection-validation-required" value="true" />


此外,有关更多信息,在我的 hibernate.properties 文件中,我有以下设置:

hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://ip:3306/database100(not database1)
hibernate.connection.username=user1
hibernate.connection.password=passwrod
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.show_sql=true
jpa.dialect=org.springframework.orm.jpa.vendor.HibernateJpaDialect
jpa.vendor.adapter=HibernateJpaVendorAdapter
java mysql hibernate mysql-connector c3p0
1个回答
-1
投票

我们今天遇到了同样的问题(请求太多,c3p0,mysql 5 -> 8)。你能解决吗? 谢谢

© www.soinside.com 2019 - 2024. All rights reserved.