0

I just now trying connect MySQL data base in Grails. This is my old data base configuration:

dataSource {
    pooled = true
    jmxExport = true
    driverClassName = "org.h2.Driver"
    username = "sa"
    password = ""
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
//    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
    cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
    singleSession = true // configure OSIV singleSession mode
    flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}

// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
            properties {
               // See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
               jmxEnabled = true
               initialSize = 5
               maxActive = 50
               minIdle = 5
               maxIdle = 25
               maxWait = 10000
               maxAge = 10 * 60000
               timeBetweenEvictionRunsMillis = 5000
               minEvictableIdleTimeMillis = 60000
               validationQuery = "SELECT 1"
               validationQueryTimeout = 3
               validationInterval = 15000
               testOnBorrow = true
               testWhileIdle = true
               testOnReturn = false
               jdbcInterceptors = "ConnectionState"
               defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
            }
        }
    }
}

I've coppied in DataSource.groovy example from a docs, I know, what in my case, something of it may be wrong:

    dataSource {
 pooled = true
 jmxExport = true
 url = "jdbc:mysql://localhost:3306/:my_database"
 driverClassName = "com.mysql.jdbc.Driver"
 dialect = org.hibernate.dialect.MySQL5InnoDBDialect
 username = "sa"
 password = ""
}
hibernate {
 cache.use_second_level_cache = true
 cache.use_query_cache = false
//    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
 cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
 singleSession = true // configure OSIV singleSession mode
 flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}

// environment specific settings
environments {
 development {
     dataSource {
         dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
         url = "jdbc:mysql://localhost:3306/:my_database"
     }
 }
 test {
     dataSource {
         dbCreate = "update"
         url = "jdbc:mysql://localhost:3306/:my_database"
     }
 }
 production {
     dataSource {
         dbCreate = "update"
         url = "jdbc:mysql://localhost:3306/:my_database"
         properties {
            // See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
            jmxEnabled = true
            initialSize = 5
            maxActive = 50
            minIdle = 5
            maxIdle = 25
            maxWait = 10000
            maxAge = 10 * 60000
            timeBetweenEvictionRunsMillis = 5000
            minEvictableIdleTimeMillis = 60000
            validationQuery = "SELECT 1"
            validationQueryTimeout = 3
            validationInterval = 15000
            testOnBorrow = true
            testWhileIdle = true
            testOnReturn = false
            jdbcInterceptors = "ConnectionState"
            defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
         }
     }
 }
}

Also, I've downloaded an archive with such content: docs folder, src folder, my-sql-connector-java-5.1.35-bin.jar. I've moved this jar-file in lib folder of my project. These errors I get when my project run:

2015-04-21 15:33:19,986 [localhost-startStop-1] ERROR pool.ConnectionPool  - Unable to create initial connections of pool.
Message: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
14
  • 1
    make sure mysql listen localhost:3306, try telnet localhost 3306 to test it, for example Apr 21, 2015 at 11:59
  • also I suggest with basic configuration, w/o properties section. and only after you'll get it working, only then use custom options, if you really need it Apr 21, 2015 at 12:01
  • am not sure about this but do you really need to manually download the mysql connector. On my project I a only seeing runtime 'mysql:mysql-connector-java:5.1.24' dependency on build config ( I did not setup my project myself.)
    – dsharew
    Apr 21, 2015 at 13:48
  • @Igor Artamonov, localhost wasn't started. It has been fixed. Also I add 'mysql:mysql-connector-java:5.1.24' dependency. And dbCreate-value has been changed to create. Now I get such error: Message: Access denied for user ''@'localhost' to database 'my_database'. How it may be if username-value is not empty string? PS. Also I've set up an empty password.
    – pragmus
    Apr 21, 2015 at 14:14
  • 1
    It means you have not created database yet.
    – Ramsharan
    Apr 21, 2015 at 18:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.