繁体   English   中英

createDatabaseIfNotExist=true 在 Maven 项目中的 .properties 文件中不起作用

[英]createDatabaseIfNotExist=true not working in .properties file in maven project

我有一个连接到已经存在的数据库的 Maven 项目。 但是我想改变它,以便如果数据库不存在。 它被创建。 所以我在这个额外的代码中添加了?createDatabaseIfNotExist=true到这一行。

dataSource.url=jdbc:mysql://localhost/rays-database?createDatabaseIfNotExist=true

我有很多错误,所以我的问题是; 为了使用 ?createDatabaseIfNotExist=true 是否缺少任何额外的配置

我还尝试添加端口号,这没有任何我没想到的区别。

dataSource.url=jdbc:mysql://localhost:3306/rays-database?createDatabaseIfNotExist=true

这是我的 .properties 文件:

 dataSource.driverClassName=com.mysql.jdbc.Driver
 dataSource.url=jdbc:mysql://localhost/rays-database?createDatabaseIfNotExist=true
 dataSource.username=root
 dataSource.password=

 hibernate.dialect=org.hibernate.dialect.MySQLDialect
 hibernate.show_sql=true
 hibernate.hbm2ddl.auto=create

请检查为什么 Hibernate 不为 MySQL 创建数据库? . 希望它有帮助。你遇到什么样的错误?

你可以试试这个,你必须在db名称上添加端口并删除这个(-)。

spring.datasource.url = jdbc:mysql://127.0.0.1:3306/DbName?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false&useUnicode=yes&characterEncoding=UTF-8&allowPublicKeyRetrieval=true

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM