Configure Liferay with My SQL or any other Database rather than HSQL DB

Liferay by default comes with HSQLDB configured. HSQLDB is generally used for development purposes and it’s not recommended for Production.

If you observed the Liferay server log then you will come to know that Liferay will put log something like

“Liferay is configured to use Hypersonic as its database. Do NOT use Hypersonic in production. Hypersonic is an embedded database useful for development and demo’ing purposes. The database settings can be changed in portal.properties.

which clearly shows, HSQLDB is not recommended for production.

In Production, generally MySQL or any other DB is used (like MS-SQL or Oracle). So it’s always better way to have same environment for development as in production. (Like JDK Version, Liferay version, DB and its version etc).

I would recommended to look at index page ‘A Complete Liferay Guide‘ to browse all topics about liferay.

Suppose, in your production environment, you have used MySQL so its advisable to Configure Liferay with MySQL for your development environment also.

Configure Liferay with MySQL


In this article we will see how to Configure Liferay with MySQL. This requires change in configuration so that it points to MySQL rather than HSQLDB.


create portal-ext.properties file under your Tomcat bundle(Liferay server) folder as shown in below screenshot.
Configure Liferay with MySQL - Configuring Database connection details in portal-ext.properties in LiferayNext, add following content in it.




Explanation:-

  • The first line shows the driver name
  • The second line form a DB url. localhost is the host name. If your MySQL DB is located on remote machine, you have to give host name(localhost in our case) or IP address of that machine. Next to it is techblog which is nothing but the schema in MySQL which will create shortly. The rest are the parameters like Character encoding and uni-code etc.
  • The third and fourth properties shows the username and password of MySQL Db
Next we have to create new schema in MySQL. You no need to create any table. Just create blank schema and Liferay will create all tables,indexes and pre-populated values.
 
Important Note:-  The MySQL schema should be matched with the schema name which we defined in above portal-ext.properties file. (techblog in our case)
 

So let’s create blank schema in MySQL. Give its name as techblog

Configure Liferay with MySQL - New-DB-Schema

 

Initially there won’t be any tables.

Now start the Liferay server. (If Liferay server is already started,then you need to stop the server and then start)


First time during start up it will take some time ,as it will create all Tables,index and pre-populated values. Once the Liferay server is started, you may revisit the techblog schema and confirm that the tables are created properly.


Also from tomcat log, you can observed that now it will take MySQL dialect rather than HSQLDB. It’s also possible to configure liferay with other database in similar way we configure Liferay with MySQL here.


And its done. Feel free to ask any questions. I will try my best to get the answers.

I would recommended to look at index pag
e ‘A Complete Liferay Guide‘ to browse all topics about liferay.

Share This Post

8 Comments - Write a Comment

    1. Hello Sai,

      Per my knowleget, there no book which gives you complete in depth of Liferay. You need to refer various books, liferay forum, liferay documentation and other personal blogs to get an idea.

      Feel free to ask any questions / give suggestion.

      Regards
      Nilang

      Reply
  1. I exactly did the same and I got this error:
    15:09:41,292 ERROR [localhost-startStop-1][DataSourceFactoryImpl:110] Unable to lookup jdbc/LiferayPool
    javax.naming.NameNotFoundException: Name [jdbc/LiferayPool] is not bound in this Context. Unable to find [jdbc].

    Can some one please help me?

    Reply
    1. Hi Vineela,

      Welcome to Tech blog and sorry for late response. From the log, it seems issues is not with the Liferay but with the Data source that you configured (JNDI) pls check it

      Regards
      Nilang

      Reply
  2. Hello Sir,

    Could you please post an article on how to set up all the necessary environment variables to begin the Liferay Development? Of late, I am getting lots of errors to start the tomcat itself.

    Thanks-Mahesh

    Reply
    1. Hi Mahesh,

      Welcome to Techblog. May I know which version of liferay you are trying to configure ? May I have your error stack trace. Please provide this info so that I can guide you properly.

      Reply
  3. Hi –

    I added mysql to liferay by following your post. However, once I closed Eclipse and restarted it, now I get an error saying “Unable to find jdbc and it says jdbc/mydb not found in this Context”
    I googled and tried a few things but nothing seems to fix the issue and it feels like some file is cached somewhere that is causing the problem. Any ideas?
    Thanks!

    Reply
    1. Hi,
      Welcome to Techblog. I assume that you put your db entries in context.xml file from eclipse. Stop Eclipse and make sure that this entry(About data source) is present in context.xml. If not then go to Liferay-Tomcat/conf folder and open context.xml file in some editor like notepad++ and then add data source entry.
      After this, when you start eclipse, do same changes in context.xml file you are able to see from server folder of eclipse.

      Now start server and then restart eclipse and check it. Hopefully it should work.

      Regards
      Nilang

      Reply

Post Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.