Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails and default mysql encoding

I want to configure my Grails application running with MYSQL to set the database and its table to utf-8. How can I achieve that?

Here is my DataSource.groovy:

environments {
    development {
        dataSource {
            dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
            driverClassName = 'com.mysql.jdbc.Driver'
            username = 'login'
            password = 'password'
            url = "jdbc:mysql://127.0.0.1:3306/database?autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8"
            dialect = org.hibernate.dialect.MySQL5InnoDBDialect
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
        }
    }
    production {
        dataSource {
            dbCreate = "update"            
            driverClassName = 'com.mysql.jdbc.Driver'
            username = 'login'
            password = 'password'
            url = 'jdbc:mysql://localhost:3306/database?autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8'
            dialect = org.hibernate.dialect.MySQL5InnoDBDialect
            properties {
                validationQuery="select 1"
                testWhileIdle=true
                timeBetweenEvictionRunsMillis=900000
            }
        }
    }
}

But grails always create database and table with latin1

How can I make the Grails app to create utf-8 encoded databases and tables?

like image 339
Snite Avatar asked Mar 20 '23 07:03

Snite


1 Answers

Try this

url="jdbc:mysql://127.0.0.1:3306/database?useUnicode=true&characterEncoding=UTF-8"

If still getting error then create database as

CREATE DATABASE database CHARACTER SET utf8 COLLATE utf8_general_ci;
like image 71
MKB Avatar answered Mar 28 '23 13:03

MKB