Changing H2 database admin user & password within Grails

942 views Asked by At

Working with Grails 2.3.3 I want to change the sa password for my H2 db or possibly replace sa with a different username with the same admin rights.

If I change the sa password in the dbconsole using the setpassword command and then update the password in the datasource.groovy file is that all I need to do? Or are there other configuration files in the Grails environment I need to update?

I tried to improve security by creating a new user with admin rights in the dbconsole. I then changed the username and password in the DataSource.groovy file. But the application failed to come up and I got an error 'Unable to create initial connections pool - wrong username or password' presumably the sa user is setup elsewhere in the environment. It would be useful to get know where all the db login values are defined?

1

There are 1 answers

2
Burt Beckwith On

DataSource.groovy is the only place that Grails looks for database connection info. A plugin or a custom DataSource/connection pool could be configured outside of there, but Grails itself only looks there.

Are you using a file-based H2 database, or starting it outside of Grails as a standalone server? In those cases it should be sufficient to make the change in the database and the corresponding changes in DataSource.groovy. If you're using the in-memory database, your user extra user will be lost when you restart the app.