Pages

Sunday, November 23, 2014

Grails and XAMPP MySQL database configuration or any external DB

Not much happening lately. End of the year, have to study a little bit not to get kicked out.

SUBJ: as usually, couldnt find an easy tutorial, so im making one.


  1.  Install XAMPP, launch it. 
  2.  Check the mysql config > my.ini. Remember the user, password and port.
  3. In your grails BuildConfig.groovy add this line:

    dependencies {

    ...

    runtime 'mysql:mysql-connector-java:5.1.34'

    ...

    }

    ...
  4. In your DataSource.groovy comment the defaule values and add your own:
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    username = "username from the config file"
    password = "password from the config file"
  5. There are the environment specific settings. The dbCreate = 'create' means that a new DB is created each time you run the app. Change it to 'update' and the DB will be persisted and updated each time.

         url = "jdbc:mysql://localhost:PORT_FROM_CONFIG_FILE_HERE/dev_db"

    Change the url to the DB schema. Not that you have to create it first in your DB. (I used MySQL workbench to connect to a running XAMPP DB, and created a schema)
  6. Basically that is it, now your app in development mode (or the mode you edited in the environment settings) will use the database you specified. Just remember that you must start the Apache too in XAMPP. 
  7. Oh, and you possibly need to grant permission for the user you defined, it is done through XAMPP mysql admin button.

No comments:

Post a Comment