Here are the steps to configure your Grails application to work with a MySQL database.
- Put the MySQL Connector J driver class in the lib folder of your Groovy App.
- In the DataSource.groovy file remove the default HSQLDB information and replace with MySQL specific configuration. (Sample file using a database called ‘books’ is shown below)
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = "admin"
}
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop"
url = "jdbc:mysql://localhost:3306/books"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/books"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/books"
}
}
}