Grails自带的HSQLDB数据库,但是更习惯使用MySql.便把数据库改成MySql的.呵,很简单,只是改的过程中闹了点小笑话,都怪自己马虎啊.
1.先下载MySql的驱动, http://www.mysql.com/products/connector/j/
2.将MySql的Jar包放到项目的lib文件夹下
3.修改grails-app\conf文件夹下的DataSource.groovy文件的DataSource:
dataSource {
pooled = false
driverClassName = "com.mysql.jdbc.Driver" //将原来的HSQLDB的驱动名改成MySql的,一定要注册变量的大小写啊,我开始就是将driverClassName的大小写搞错了,结果找了半天错误,哈.
username = "puras" //MySql的用户名
password = "123456" //相应的密码
}
4.修改DataSource.groovy文件:
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop','update'
url = "jdbc:mysql://localhost/ibmhp?useUnicode=true&characterEncoding=UTF8 " //将URL改成MySql的,与Java的一样
}
}
5.成功啦~~~~
rails-app\conf\DataSource.groovy:
- dataSource {
- // pooled = true
- // driverClassName = "org.hsqldb.jdbcDriver"
- // username = "sa"
- // password = ""
- pooled = false
- driverClassName = "com.mysql.jdbc.Driver"
- username = "root"
- password = "888888"
- }
- hibernate {
- cache.use_second_level_cache=true
- cache.use_query_cache=true
- cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
- }
- // environment specific settings
- environments {
- development {
- dataSource {
- dbCreate = "create-drop" // one of 'create', 'create-drop','update'
- // url = "jdbc:hsqldb:mem:devDB"
- url = "jdbc:mysql://localhost:3306/contact_dev?useUnicode=true&characterEncoding=UTF-8"
- }
- }
- test {
- dataSource {
- dbCreate = "update"
- // url = "jdbc:hsqldb:mem:testDb"
- url = "jdbc:mysql://localhost:3306/contact_test?useUnicode=true&characterEncoding=UTF-8"
- }
- }
- production {
- dataSource {
- dbCreate = "update"
- // url = "jdbc:hsqldb:file:prodDb;shutdown=true"
- url = "jdbc:mysql://localhost:3306/contact_prod?useUnicode=true&characterEncoding=UTF-8"
- }
- }
- }