Monday, September 16, 2013

Getting Started with Grails and MySQL database

Is is so much simple.

Create a file suppose named 'db-config.properties' in 'conf' folder with the following contents:
dataSource.driverClassName = com.mysql.jdbc.Driver
dataSource.username = root
dataSource.password =
dataSource.url = jdbc:mysql://localhost/license?useUnicode=yes&characterEncoding=UTF-8
dataSource.dbCreate = update
dataSource.logSql = true
dataSource.insertDummy = true
dataSource.dialect = org.hibernate.dialect.MySQL5InnoDBDialect

/* Your custom class to do some extra work if need */
dataSource.configClass = src.gorm.GormConfiguration;


Where root is your database username.
Where 'license' is your database name.

And make a entry in 'Config.groovy' file under 'conf' folder as following:
grails.config.locations = [ "classpath:db-config.properties" ]

And you need to must do one thing is to download a  java-mysql connector and put it inside lib folder of your project.
Sometimes you need to clean your project to adjust these changes.

You can use more config file like this as:

grails.config.locations =
[
    "classpath:db-config.properties",
    "classpath:some-config.properties" ,
    "file:${userHome}/.grails/${appName}-config.propertis"
]

No comments:

Post a Comment