Grails和默认的mysql编码

Sni*_*ite 3 mysql grails encoding

我想配置运行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
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是grails总是创建数据库和表 latin1

如何创建Grails应用程序来创建utf-8编码数据库和表?

MKB*_*MKB 7

试试这个

url="jdbc:mysql://127.0.0.1:3306/database?useUnicode=true&characterEncoding=UTF-8"
Run Code Online (Sandbox Code Playgroud)

如果仍然出现错误,则将数据库创建为

CREATE DATABASE database CHARACTER SET utf8 COLLATE utf8_general_ci;
Run Code Online (Sandbox Code Playgroud)