Getting Started with Grails and MySQL
1. Create a database in MySQL.
mysql> CREATE DATABASE bank_dev;
mysql> CREATE DATABASE bank_test;
mysql> CREATE DATABASE bank_prod;
2.Add the MySQL driver to project.
Download the jar file(i am using mysql-connector-java-5.0.4-bin.jar) and put it in your $project/lib directory
3.change DataSource.groovy
The complete code should look like this
dataSource
// pooled = true
// jmxExport = true
// driverClassName = "org.h2.Driver"
// username = "sa"
// password = ""
pooled = true
jmxExport = true
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
hibernate
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
// cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
singleSession = true // configure OSIV singleSession mode
// environment specific settings
environments
development
dataSource
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
// url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost:3306/ncbank_dev?useUnicode=true&characterEncoding=UTF-8"
test
dataSource
dbCreate = "update"
// url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost:3306/ncbank_test?useUnicode=true&characterEncoding=UTF-8"
production
dataSource
dbCreate = "update"
// url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:mysql://localhost:3306/ncbank_prod?useUnicode=true&characterEncoding=UTF-8"
properties
// See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
jmxEnabled = true
initialSize = 5
maxActive = 50
minIdle = 5
maxIdle = 25
maxWait = 10000
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
jdbcInterceptors = "ConnectionState"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
Getting Started with Grails and MySQL
No comments:
Post a Comment