Apache Tutorials
Configuring OfBiz To Use A MySQL Database
Installing Apache OfBiz
Learning to use mod_rewrite

Configuring OfBiz To Use A MySQL Database

While OfBiz ships with the capable Derby database you might decide you want to use another database such as MySQL. OfBiz can easily be configured to use a variety of external database sources through fairly simple configuration changes. The entityengine.xml file will have to be edited and the appropriate JDBC connector will have to be installed.

Configuring OfBiz

The first thing to do is to edit {ofbiz}/framework/entity/config/entityengine.xml. Scroll through the file, take note of the delegator entries. These are used for declaring the different data store types available and selecting the one to use. The "default" one is the one that OfBiz uses. Verify there is a field type entry for the database you plan on using.

Basic derby delegator:

    <delegator name="default" entity-model-reader="main" 
          entity-group-reader="main" entity-eca-reader="main" 
          distributed-cache-clear-enabled="false">
        <group-map group-name="org.ofbiz" 
               datasource-name="localderby"/>
        <group-map group-name="org.ofbiz.olap" 
               datasource-name="localderbyolap"/>
    </delegator>

Basic MySQL delegator:

    <delegator name="default" entity-model-reader="main" 
          entity-group-reader="main" entity-eca-reader="main" 
          distributed-cache-clear-enabled="false">
        <group-map group-name="org.ofbiz" 
                datasource-name="custommysql"/>
        <group-map group-name="org.ofbiz.olap" 
                datasource-name="customolapmysql"/>
    </delegator>

The datasource entries are the database connection and configuration definitions for each data store type. Look at the derby statements, notice there's three of them. The ofbiz store, the odbc connector, and the olap (online analytic processing) store. Make a copy of the entire datasource statement for the database being deployed. There's no need to copy the odbc datasource.

Example MySQL datasource statement:

    <datasource name="custommysql"
            helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"
            field-type-name="mysql"
            check-on-start="true"
            add-missing-on-start="true"
            check-pks-on-start="false"
            use-foreign-keys="true"
            join-style="ansi-no-parenthesis"
            alias-view-columns="false"
            drop-fk-use-foreign-key-keyword="true"
            table-type="InnoDB"
            character-set="latin1"
            collate="latin1_general_cs">
        <read-data reader-name="seed"/>
        <read-data reader-name="seed-initial"/>
        <read-data reader-name="demo"/>
        <read-data reader-name="ext"/>
        <inline-jdbc
                jdbc-driver="com.mysql.jdbc.Driver"
                jdbc-uri="jdbc:mysql://127.0.0.1/ofbiz?autoReconnect=true"
                jdbc-username="ofbiz"
                jdbc-password="ofbiz"
                isolation-level="ReadCommitted"
                pool-minsize="2"
                pool-maxsize="250"/>
        <!-- <jndi-jdbc jndi-server-name="localjndi" 
                jndi-name="java:/MySqlDataSource" isolation-level="Serializable"/> -->
    </datasource>

Next adjust the jdbc-username & jdbc-password, and set the mysql host and database name in the jdbc-uri line. Make a copy of this new datasource and append olap to the database name in the jdbc-uri line.

Installing the JDBC Connector

For OfBiz to be able to connect to the database an appropriate JDBC connector must be installed into {ofbiz}/framework/entity/lib/jdbc/. JDBC connectors are usually provided by the database provider.

Install the mysql-java-connector

First download the connector from http://dev.mysql.com/downloads/connector/j/ and uncompress the archive. Then copy mysql-connector-java-X.X.X-bin.jar to {ofbiz}/framework/entity/lib/jdbc/.

 # cp mysql-connector-java-X.X.X-bin.jar {ofbiz}/framework/entity/lib/jdbc/

Next create the ofbiz and ofbizolap databases and associated accounts declared in the datasource statements. The databases will be populated during the and install, run-install-seedext, etc.

New Content

Related Information
Installing Apache OfBiz