configure grails to create the database if it doesn't exist.

∥☆過路亽.° 提交于 2019-12-11 03:35:31

问题


I have the following settings on a new grails project:

dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
    username = "sa"
    password = ""
}

environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:mysql://localhost/myapp?useUnicode=yes&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8"
            username = "root"
            password = ""
        }
    }
}

when I run my app it fails with an error: Error creating bean with name 'transactionManagerPostProcessor':

This error goes away when I manually go to my database and create a database called myapp

I thought the create-drop setting in dbCreate is suppose to create the db if it does not exist.

Question

How can I configure the settings so that the database gets created when it does not exist in the MySQL


回答1:


Creating the database itself is impractical because it is very vendor-specific, even more so than the DDL to create tables, sequences, etc. You often need to specify access rules, storage options, etc.

Hibernate will generate and run the schama DDL but you have to start the process by creating the database itself except for simple databases like H2.



来源:https://stackoverflow.com/questions/19479704/configure-grails-to-create-the-database-if-it-doesnt-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!