MySQL: Connecting MySQL with Groovy/Grails
This documentation is part of the Getting started guide. View the full guide here: How to get started with MySQL.
👋 Welcome to the Stackhero documentation!
Stackhero offers a ready-to-use MySQL cloud solution that provides a host of benefits, including:
- Unlimited connections and transfers.
- phpMyAdmin web UI included.
- Effortless updates with just a click.
- Optimal performance and robust security powered by a private and dedicated VM.
Save time and simplify your life: it only takes 5 minutes to try Stackhero's MySQL cloud hosting solution!
Here is an example of configuring your Grails application to connect to MySQL:
dataSource {
pooled = true
driverClassName = "com.mysql.cj.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL8Dialect
// SSL-specific properties
properties {
useSSL = true
requireSSL = true
verifyServerCertificate = true
sslMode = "REQUIRED"
}
}
environments {
production {
dataSource {
dbCreate = "none"
url = "jdbc:mysql://" + System.env.STACKHERO_MYSQL_HOST + ":" + System.env.STACKHERO_MYSQL_PORT + "/root?useSSL=true&requireSSL=true&verifyServerCertificate=true&sslMode=required" // You can replace "/root" with your preferred database.
username = "root" // It is a good idea to create a dedicated user for your application.
password = System.env.STACKHERO_MYSQL_ROOT_PASSWORD
properties {
maxActive = 50
minEvictableIdleTimeMillis = 1800000
timeBetweenEvictionRunsMillis = 1800000
numTestsPerEvictionRun = 3
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
validationQuery = "SELECT 1"
}
}
}
}