Configure Liferay-4.4.2 with Glassfish Bundle to Use MySQL on Gentoo

  1. Install mysql server:
    1. # emerge -pv dev-db/mysql
    2. # USE=-berkdb emerge -v dev-db/mysql
      (Berkeley DB is deprecated in msyql, so no need to install it)
    3. At the end of above command, it suggested to run the following:
      # emerge --config =dev-db/mysql-5.0.54
      (This command will setup the mysql root pwd)
    4. # rc-update add mysql default
    5. # /etc/init.d/mysql start
  2. Install MySQL JDBC connector:
    1. Install the package
      # emerge -pv dev-java/jdbc-mysql
      I had jdk-1.6 installed earlier. Now the jdbc-mysql depends on jdk-1.5. So I have two jdk versions in this systems now.
    2. Copy the JDBC driver to glassfish domains/<liferay_domain>/lib subdir:
      % cd domains/domain1/lib
      %  ln -s /usr/share/jdbc-mysql/lib/jdbc-mysql.jar
  3. Create the database:
    # mysql -u root -p <<< "create database lportal;"
  4. Download the mysql script from Liferay Additional Files, and run
    # mysql -u root -p < create-mysql.sql
  5. Create a separate liferay mysql user:
    # mysql -u root -p
    mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON lportal.*
            -> TO newuser'@'localhost' IDENTIFIED BY 'password';
  6. Restart glassfish:
    1. % bin/asadmin stop-domain
    2. % bin/asadmin start-domain
  7. Open localhost:4848 to enter glassfish admin console.
    The default username is admin and the password is adminadmin.
  8. In the Glassfish admin console, go to Resources/JDBC/Connection Pools and create a connection pool to connect to the lportal database.
    Create mysql JDBC connection pool in Glassfish
    Click "Next" to continue:
    In the next window, in the section of "Additional Properties", change the values in these fields:
    1. "URL" and "Url" fields. The format of these two fields are "jdbc:mysql://localhost:3306/databasename". If mysql is running in a different host, change the "localhost" to that hostname. "databasename" would be lportal in out case here.
    2. "User" field. Set the lportal mysql database username we created earlier.
    3. "Password" fields. Set the lportal mysql database user's password.
  9. In the Glassfish admin console, go to Resources/JDBC/JDBC Resources, create a JDBC resource with the name jdbc/LiferayPool, and associate it with the connection pool created in the previous step. If the LiferayPool exists already, edit it.
  10. Now we can restart the Glassfish.
    In my case, at first, the Liferay - Glassfish didn't start. I checked glassfish domains/<liferay domain>/logs/server.log, saw that it complained about not being able to access mysql. Then open glassfish domains<liferay domain>/config/domain.xml, and found out password was entered wrong. Fixed the password and Glassfish started fine!

References: