Though I don’t really recommend people to use a “shared” database, I do prefer running on a real database once in a while rather than relying on the embedded Derby that comes with Glassfish. The main reason is I just want one database application running for whatever tooling I need to use and have it run as a service even though I am the only one using it. That being said, I chose MySQL primarily because it is readily installable on my devops server running Ubuntu.
Before going on, first create a user/schema on the MySQL server.
mysql -u root -p CREATE USER 'glassfish'@'%' IDENTIFIED BY 'password'; CREATE DATABASE glassfish; GRANT ALL PRIVILEGES ON glassfish . * TO 'glassfish'@'%';
Then on the local Glassfish installation, add the MySQL Java Connector into the glassfish/lib
folder. Restart the Glassfish server.
Start up asadmin
and type the following command to create the JDBC datasource pool, update the default JPA resource pool name and ping the connection pool.
create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlXADataSource --restype javax.sql.XADataSource MySqlXAPool set resources.jdbc-connection-pool.MySqlXAPool.property.User=glassfish set resources.jdbc-connection-pool.MySqlXAPool.property.password=password set resources.jdbc-connection-pool.MySqlXAPool.property.Url=jdbc:mysql://server:3306/glassfish ping-connection-pool MySqlXAPool set resources.jdbc-resource.jdbc/__default.pool-name=MySqlXAPool