如果数据库不存在,请配置grails以创建数据库。 [英] configure grails to create the database if it doesn't exist.

查看:270
本文介绍了如果数据库不存在,请配置grails以创建数据库。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

运行我的应用程序失败,出现错误:创建名为'transactionManagerPostProcessor'的bean时出错:



当我手动去我的数据库并创建一个名为 myapp 的数据库



我认为dbCreate中的 create-drop 设置是假设它创建的数据库不存在。



问题

如何配置设置以便创建数据库当它不存在于MySQL中时

解决方案

创建数据库本身是不切实际的,因为它非常适合供应商,比DDL创建表,序列等你经常需要指定访问规则,存储选项等。

Hibernate会生成并运行schama DDL,但是你有通过创建数据库本身来启动进程,除了简单的数据库(如H2)。


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

解决方案

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.

这篇关于如果数据库不存在,请配置grails以创建数据库。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆