« 返回到 Starting with...

Database Configuration

Introduction #

Liferay comes with a default database called HSQL or "hypersonic." This is not meant for production use however! You need to switch to a real database to use Liferay. This page documents how to change the default database system.

Liferay 6.0 & 6.1 #

Database configuration in 6.0, 6.1 is the same as 5.2. Find your corresponding JDBC settings for your database, and put them into portal-ext.properties file, which can be found at

${CATALINA_HOME}/webapps/ROOT/WEB-INF/classes
where CATALINA_HOME variable is the liferay-portal-${liferay-version}/tomcat-${tomcat-version} directory

If it doesn't exist, you need to create it. For a full list of database-related portal-properties that you can paste in to make your database work, see Database Portal Properties. For more information, please read the Liferay 5.2 section which contains more details in case you need advanced configuration.

Liferay 5.2 #

In versions 5.2 and after, the configuration of the database is set in a single file, portal-ext.properties, for all application servers. Add the example below to set up MySQL.

jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=
jdbc.default.password=

As of 5.2.2 you can use the connection pools provided by the application server by specifying the JNDI name to be used in portal-ext.properties using the following property:

jdbc.default.jndi.name=jdbc/LiferayPool

This re-establishes the way connections are handled to the behaviour of version 5.1.x

If you do not have an existing portal-ext.properties file, you can create one and save it to:

{liferay-home}\{tomcat}\webapps\ROOT\WEB-INF\classes

for Tomcat. (To find out where to put portal-ext.properties for other app servers, please refer to the Portal Administrator's Guide.)

The portal.properties file has examples for all the main databases supported. However, if you are using the bundled / download version of Liferay (instead of building from source), you will not be able to find portal.properties in your installation. (Refer to page 127 of the Portal Administrator's Guide Second Edition for an explanation why this is the case.) Instead, you can find a copy of portal.properties here for reference:

http://svn.liferay.com/repos/public/portal/branches/5.2.x/portal-impl/src/portal.properties

Again, once you've referenced portal.properties to understand what settings are available, make the appropriate additions to your portal-ext.properties file.

Note that this system uses the apache commons pool for pooling connections to the database. If you prefer to use the pooling mechanism provided by the portal application server you can still do that through spring. In particular add this to the ext-spring.xml file:

<bean id="liferayDataSource"
class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
       <property name="targetDataSource">
               <bean
class="com.liferay.portal.spring.jndi.JndiObjectFactoryBean">
                       <property name="jndiName" value="jdbc/LiferayPool" />
               </bean>
       </property>
</bean>

This file can be found in your extension environment. If you are not using this environment just create an Spring configuration file with that name and add it to the META-INF dir of your installation.

For GlassFish Application server:

Set other properties e.g. using application server web admin interface. Idle Timeout = ?? seconds (less than timeout of your database server configuration)

Connection Validation (Validate connections, allow server to reconnect in case of failure)

Required=True
Validation Method=Table
Table Name=User_

For MySql, make sure you create the database first;

create database lportal character set utf8;

Note : Note that all these instructions apply to the core Liferay installation, but some installed plugins (for example WOL in Liferay 5.2) may have its own database configuration. See http://www.liferay.com/community/forums/-/message_boards/message/4526420 for a discussion specific to the WOL plugin.

Liferay 5.1 and prior #

In Liferay v5.1 and before, the configuration was specific for each application server. This section explains how to configure tomcat by modifying the ROOT.xml file. For other application servers please check their documentation.

ROOT.xml can be found in tomcat\conf\Catalina\localhost\ROOT.xml. for reference, at the end of this article I have included an excerpt of ROOT.xml from Liferay 4.3.x

Notice there are sample entries in this file for many different databases. By default, Liferay uses Hypersonic (lightweight db used for development purposes). Notice that all entries are commented out except for the Hypersonic entry. Since we want to change Liferay to point to MySQL, we will simply

1) Comment out the Hypersonic entry,

<!-- Hypersonic -->

<!--<Resource
	name="jdbc/LiferayPool"
	auth="Container"
	type="javax.sql.DataSource"
	driverClassName="org.hsqldb.jdbcDriver"
	url="jdbc:hsqldb:lportal"
	username="sa"
	password=""
	maxActive="20"
/>-->

2) and uncomment the MySQL entry (or which ever entry you need for your database).

<!-- MySQL -->

<Resource
	name="jdbc/LiferayPool"
	auth="Container"
	type="javax.sql.DataSource"
	driverClassName="com.mysql.jdbc.Driver"
	url="jdbc:mysql://localhost/lportal?useUnicode=true&amp;characterEncoding=UTF-8"
	username=""
	password=""
	maxActive="20"
/>

make sure that you change the value for url to point to your MySQL database url, and also fill in a username and password.

Including the JDBC driver #

The next step is to make sure that tomcat has the appropriate JDBC driver so that it can 'talk' to this database. You can find these drivers online, however, for your convenience, we have included the MySQL driver (along with many others) in the portal code at the following path:

portal\lib\development\mysql.jar

For Liferay 5.1.1, if you are using Oracle 9i, then there are some issues with ojdbc14.jar. Instead of that use other jars like ojdbc14_g.jar for connecting to database.

If we are..

  • developing in the EXT environment, we need to copy the JDBC driver to this path:
    • ext\ext-lib\global\mysql.jar
  • developing directly from Portal Core (not recommended), copy the driver here:
    • portal\lib\global\mysql.jar
  • only using the Tomcat bundle, copy the driver here:
    • tomcat\common\lib\ext\mysql.jar

Creating the database and tables #

You will first need to create the database, make sure that this matches the value in the url of your ROOT.xml.

For most versions of Liferay, you will have 2 sets of sql scripts, one which will create the Liferay tables with sample data (the Liferay public website) or with just the bare minimal data. You can find both sets of scripts in the portal code:

portal\sql\portal\portal-mysql.sql

and

portal\sql\portal-minimal\portal-minimal-mysql.sql

If you..

Manually creating the table #

Run the appropriate script against your database.

Automatically creating the tables #

Starting in 4.3, you only need to create the database and Liferay will automatically run the appropriate script to create all the necessary tables for you.

in portal.properties, there is a property that you can set which will determine if the portal will create a minimal version of Liferay or a version which is pre-populated with sample data.

##
## Schema
##

    #
    # Set this to true to automatically create tables and populate with default
    # data if the database is empty.
    #
    schema.run.enabled=true

    #
    # Set this to to true to populate with the minimal amount of data. Set this
    # to false to populate with a larger amount of sample data.
    #
    schema.run.minimal=false

If you wanted Liferay to automatically create only the necessary Liferay tables for you, then add the following values in your portal-ext.properties (tomcat\webapps\ROOT\WEB-INF\classes\portal-ext.properties)

    schema.run.enabled=true
    schema.run.minimal=true

Reference #

Excerpt of ROOT.xml in 4.3.x #

<Context path="" crossContext="true">

	<!-- DB2 -->

	<!--<Resource
		name="jdbc/LiferayPool"
        auth="Container"
        type="javax.sql.DataSource"
        driverClassName="com.ibm.db2.jcc.DB2Driver"
        url="jdbc:db2:lportal"
        username="db2admin"
        password="lportal"
        maxActive="20"
	/>-->

	<!-- Derby -->

	<!--<Resource
		name="jdbc/LiferayPool"
		auth="Container"
		type="javax.sql.DataSource"
		driverClassName="org.apache.derby.jdbc.EmbeddedDriver"
		url="jdbc:derby:lportal"
		username=""
		password=""
		maxActive="20"
	/>-->

	<!-- Hypersonic -->

	<Resource
		name="jdbc/LiferayPool"
		auth="Container"
		type="javax.sql.DataSource"
		driverClassName="org.hsqldb.jdbcDriver"
		url="jdbc:hsqldb:lportal"
		username="sa"
		password=""
		maxActive="20"
	/>

	<!-- MySQL -->

	<!--<Resource
		name="jdbc/LiferayPool"
		auth="Container"
		type="javax.sql.DataSource"
		driverClassName="com.mysql.jdbc.Driver"
		url="jdbc:mysql://localhost/lportal?useUnicode=true&amp;characterEncoding=UTF-8"
		username=""
		password=""
		maxActive="20"
	/>-->

	<!-- Oracle -->

	<!--<Resource
		name="jdbc/LiferayPool"
		auth="Container"
		type="javax.sql.DataSource"
		driverClassName="oracle.jdbc.driver.OracleDriver"
		url="jdbc:oracle:thin:@localhost:1521:orcl"
		username="lportal"
		password="lportal"
		maxActive="20"
	/>-->

	<!-- P6Spy -->

	<!--<Resource
		name="jdbc/LiferayPool"
		auth="Container"
		type="javax.sql.DataSource"
		driverClassName="com.p6spy.engine.spy.P6SpyDriver"
		url="jdbc:mysql://localhost/lportal?useUnicode=true&amp;characterEncoding=UTF-8"
		username=""
		password=""
		maxActive="20"
	/>-->

	<!-- PostgreSQL -->

	<!--<Resource
		name="jdbc/LiferayPool"
		auth="Container"
		type="javax.sql.DataSource"
		driverClassName="org.postgresql.Driver"
		url="jdbc:postgresql://localhost:5432/lportal"
		username="sa"
		password=""
		maxActive="20"
	/>-->

	<!-- SQL Server -->

	<!--<Resource
		name="jdbc/LiferayPool"
		auth="Container"
		type="javax.sql.DataSource"
		driverClassName="net.sourceforge.jtds.jdbc.Driver"
		url="jdbc:jtds:sqlserver://localhost/lportal"
		username="sa"
		password=""
		maxActive="20"
	/>-->

	<!-- Sybase -->

	<!--<Resource
		name="jdbc/LiferayPool"
		auth="Container"
		type="javax.sql.DataSource"
		driverClassName="net.sourceforge.jtds.jdbc.Driver"
		url="jdbc:jtds:sybase://localhost:5000/lportal"
		username="sa"
		password=""
		maxActive="20"
	/>-->

Related Articles #

Tomcat with SQL Server 2008

Building and Installing Liferay Source Code on Glassfish v2 and MySQL

Sybase configuration for Liferay

DB2 Express-C 9.5 on CentOS 5.2

Derby with Glassfish

PostgreSQL with Glassfish

Derby Java DB RDBMS

0 附件
664742 查看
平均 (2 票)
满分为 5,平均得分为 5.0。
评论
讨论主题回复 作者 日期
Hi, I have been googling and reading the wiki... Jon Goldberg 2009年2月20日 上午10:05
I am also having a problem. I interpreted the... Troy St. john 2009年2月20日 下午1:03
For MySql, make sure the database exist. It... Jerry Niu 2009年2月20日 下午3:04
It is not as complicated as it appears in this... andrew chen 2009年6月17日 下午2:33
Awesome - managed to get it working. Just one... Content Chemist 2010年1月7日 上午10:46
I have been reading the Wiki and I'm... Lisa Simpson 2009年2月23日 下午1:11
Hello Lisa, Unfortunately, this article... Richard Sezov 2009年2月24日 下午3:43
Rich, I am using the jBoss-tomcat- 5.0.0... Brian Holland 2009年4月1日 上午8:16
The first part of configuring liferay to use... Richard Sandoz 2009年4月22日 下午10:07
Lisa, also wanted to let you know the Wiki... Bryan H Cheung 2009年2月24日 下午3:51
Hi Lisa, For the MySql connect, you need to... Jerry Niu 2009年2月27日 下午12:23
I tried the technique above - ... Tom Wackerfuss 2009年3月2日 下午12:32
This seems to work, I removed the HSQL... Michael Burchill 2009年3月2日 下午8:39
It would be a cache issue in the Tomcat. It... Jonas Yuan 2009年3月6日 下午2:16
I haven't been doing much development recently,... Larry Smith 2011年3月23日 下午4:09
I've noticed that, since I'm using a very... David Thompson 2009年3月1日 下午6:50
I downloaded the 5.2.2. Bundled with Tomcat 5.5... Franklin Phan 2009年3月10日 下午3:59
Does Liferay generate any logs by default? I'm... Franklin Phan 2009年3月10日 下午4:38
Seems like I still get this Msg: 23:18:30,686... Ben L 2009年3月30日 下午4:41
Excellent! was googling & pulling my hair out... jef vratny 2009年5月4日 上午4:25
Is there a way to keep using ROOT.xml instead... Diego Toharia 2009年5月7日 上午1:33
Hi, nothing is commented about the wol-portlet... Luis Mas 2009年5月18日 上午10:15
sorry, the file should be at ... Luis Mas 2009年5月18日 上午10:35
and as wol tables are created in lportal schema... Angela Maria Russi 2009年5月18日 上午11:45
Hi All I am unable to do the DB migration. My... New2 Liferay 2009年5月20日 上午3:23
INGRES Database problem; in migration // SORRY... New2 Liferay 2009年5月20日 上午3:25
Using Oracle I need to have a databse with an... Denis Signoretto 2009年5月22日 上午1:04
404 error when going to http://hostname:8080/... general grant 2009年5月22日 上午10:58
I am having the same problem with Tomcat 5.5. ... Erika O 2009年5月27日 下午12:04
I'm trying to migrate from 5.1.2 to 5.2.3. ... Wayne Christian 2009年6月7日 上午11:26
I also seem to be getting oading... Wayne Christian 2009年6月7日 上午11:29
Hello Guys, I am new bee to Liferay, I just... Am sodi 2009年6月7日 下午5:00
Thanks Ramesh, it worked perfectly. Even... Carlos Galindo 2009年6月11日 下午2:57
hwat about Oracle hana Gebredingle 2009年7月6日 上午1:45
What is the effect of having empty values for... Peter B West 2009年7月30日 下午9:17
Someone really needs to clean this... J B 2009年8月12日 下午12:26
I have a similar issue. I just want to move... dali Laadhar 2009年9月29日 上午6:43
I also facing the same problem as like u i add... sasi kala 2010年3月31日 上午4:32
Can someone plz help me connecting to a SQl... CJ van Tonder 2009年12月14日 上午1:31
Hi, I was able to configure Liferay Portal... Prem Kashyap 2009年12月14日 上午4:19
Just found out. Actually you do not need the... Prem Kashyap 2009年12月14日 上午4:31
Thank you so much, really helpfull infos. But,... Oğuz Çelikdemir 2010年1月6日 上午12:07
Hi all, To configure liferay on oracle10g ... DarshanKumar N Bhatia 2010年4月25日 下午9:05
HI Just to say Thanks "configure liferay on... DarshanKumar N Bhatia 2010年8月7日 上午12:26
At the beginning of this page, in the area for... Kirk Stork 2010年9月10日 上午6:32
Kirk, We have been working on this, literally,... Amy Mead 2010年10月1日 下午2:16
Windows/Unix MySQL Note: Windows and unix... David H Nebinger 2011年7月23日 上午8:25
Hi All, We are having one web application, Now... Navnath Gajare 2011年10月20日 上午1:45
I have problem like this: 严重: Error waiting... Harry ni 2012年9月20日 上午2:50
Yes, there is a solution, where you can migrate... Bella fernandis 2012年12月11日 下午10:30

Hi,

I have been googling and reading the wiki and posts. I downloaded the 5.2.1 version of liferay with both tomcat 5.5 and 6. I can't figure out what file to create or edit to have liferay use mysql instead of hypersonic. I have read alot about a portal(-ext). file to create. Does anyone have an example and what directory to put in? Sorry i am more of DBA than Java developer.

Liferay v5.2 unifies the configuration of the database in a single file for all application servers. As most other configuration options you can set this up in the portal(-ext).properties file as follows (example for MySQL):

I see this from above where do i put it. Is there a way to get those sample files?

jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:my­sql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsi­ng=false
jdbc.default.username=
jdbc.default.password=

Thanks,

Jon

PS. I got it working with hypersonic is real simple..... emoticon
在 09-2-20 上午10:05 发帖。
I am also having a problem.

I interpreted the instructions above as "...if this file does not exist then create it using....".

So I did however it doesn't seem to work.

Any answers out there?
在 09-2-20 下午1:03 发帖以回复 Jon Goldberg
For MySql, make sure the database exist. It does not need to be populated, just needs to exist.
{{{
create database lportal521 character set utf8;
}}}
在 09-2-20 下午3:04 发帖以回复 Jon Goldberg
I have been reading the Wiki and I'm confused!!!! I can't find the portal.properties in 5.2 to save my life. Quoting.... "The portal.properties file has examples for all the main databases supported. " I'm unable to get this to attach to MySQL When I try to run Liferay with a MySQL configuration, I get a Tomcat 404 error message. I seem to be missing some vital file but I'll be damned if I know what it is or where to find it. I'm not that familiar with your product but I've been googling like mad and still can't come up with anything. Surely this product isn't so retarded that I can't set the database connection from an XML file. Or wait... I think that is what I'm seeing... I have to use ant and rebuild it get it to talk to a "real" database.
在 09-2-23 下午1:11 发帖。
Hello Lisa,

Unfortunately, this article assumes that the reader has certain information that the article itself does not provide.

Please take a look at our Liferay Portal Administrator's Guide here: http://www.liferay.com/web/guest/community/documentation/5_1. On page 127, there is a description of what the portal.properties file is, where to find it, and how to extend it using your own portal-ext.properties file. The file in the 5.2 version of the portal does indeed have examples for the various databases, and you can use that as a template in your portal-ext.properties file to connect to your database of choice.

Hope this helps!

--Rich
在 09-2-24 下午3:43 发帖以回复 Lisa Simpson
Lisa, also wanted to let you know the Wiki article has been updated with a direct link to portal.properties in SVN. That way you can reference it and then add the properties you want to override in your portal-ext.properties.
在 09-2-24 下午3:51 发帖以回复 Lisa Simpson
Hi Lisa,

For the MySql connect, you need to create a new blank file and name it "portal-ext.properties" and put it in the "{liferay-home}\{tomcat}\webapps\ROOT\WEB-INF\classes" folder.

Cheers,

Jerry Niu
在 09-2-27 下午12:23 发帖以回复 Lisa Simpson