【发布时间】:2014-08-07 18:52:48
【问题描述】:
我想配置运行 MYSQL 的 Grails 应用程序,以将数据库及其表设置为 utf-8。我怎样才能做到这一点?
这是我的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
}
}
}
}
但是grails总是用latin1创建数据库和表
如何让 Grails 应用程序创建 utf-8 编码的数据库和表?
【问题讨论】: