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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With