Configure MySQL with Grails

Oh Grails, you are the Holy Grail!…It makes developers life so easy and so much more pleasant. To configure MySql db with Grails application contains two simple steps:

Pre-Condition: MySql Installed, Database(Schema) created

Step 1 – Configure Connection

In the /grails-app/conf/DataSource.groovy, update you appropriated environment as following example demonstrated for development env:

development {
        dataSource {
            dbCreate = "create-drop"
            driverClassName = "com.mysql.jdbc.Driver"
            url = "jdbc:mysql://localhost/database-name"
            username = "user"
            password = "password"
        }
    } 
...

Step 2 – Instruct load MySql driver

In the /grails-app/conf/BuildConfig.groovy update ‘dependencies’ code block as following:

dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
         runtime 'mysql:mysql-connector-java:5.1.16'
    }
...

Possible Issues

Cannot load JDBC driver class ‘com.mysql.jdbc.Driver’ – If you try to run application and receive the following issue, then you have missed step 2 or specified the incorrect dependency in step 2.

One thought on “Configure MySQL with Grails

Leave a Reply

Your email address will not be published. Required fields are marked *