SQLyog 不是數據庫,它是 MySQL 的圖形化管理客戶端(類似 Navicat、Workbench)。數據庫是 MySQL Server。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"https://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- JDBC 連接 -->
<property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/your_db?useSSL=false&serverTimezone=UTC</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">123456</property>
<!-- 方言 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</property>
<!-- 連接池 (可選) -->
<property name="hibernate.hikari.maximumPoolSize">10</property>
<!-- 映射文件 -->
<mapping resource="com/entity/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
搞清「客戶端 ≠ 服務端」,Hibernate 只管連 MySQL Server,填對 URL/用戶/密碼/方言即可,參考完整 Demo 修改最快。