03 MySQL Configuration

Table of Contents

MySQL is a free, open source database, available for download at http://dev.mysql.com/ (more information can also be found at http://www.mysql.com) - also at this address, the JDBC driver for MySQL, Connector/J, can be downloaded. The Generally Available (GA) release is usually what is desired - it is best to use this instead of the Beta versions. As of this writing (5/23/05), the latest GA version of the database is 4.1.12 and is available for Windows, Mac OSX, Unix (Solaris), most flavors of Linux, and HP-UX, to name a few. The latest GA Connector/J in the 3.1 family is 3.1.14, available in a .zip and a .tar.gz. For information on how to create a database in MySQL or create the tables, you will need to refer to the documentation that came with the version of MySQL you have decided to use. There are links to MySQL documentation as well on the above site.

MySQL Configuration

Table Type

uPortal relies on database transactional support, which in MySQL is dependent upon the underlying storage engine (per-table). The default (MyISAM) is not transaction safe. The most common transactional table type on MySQL is InnoDB.

Assuming you've got the needed statements for InnoDB tables in your my.cnf file, you can change already-created MyISAM tables to Innodb tables with an ALTER TABLE statement - see the documentation for the exact syntax. Or, you can drop all your tables and re-create them with "TYPE=InnoDB" on your CREATE TABLE statements. If you're not sure about using TST (Transaction Safe Tables), do some reading on the MySQL site (http://www.mysql.com) about some of the companies and organizations that are currently using them - for instance, Slashdot.org uses MySQL InnoDB tables to handle their more than 100,000 hits per week.

Case-Sensitivity

MySQL table names are case-sensitive depending on the filesystem of the server. e.g. insensitive on Windows & Mac HFS+, Case sensitive on Unix. To prevent issues when moving between platforms it is recommended that you set:

my.cnf
[mysqld]
lower_case_table_names=1

If you have already created your database, and plan to change the lower_case_table_names system variable to 1 on Unix, you must first convert your old database and table names to lowercase before restarting mysqld with the new variable setting.

http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html

Indexing

Another thing that is really needed to use MySQL with uPortal effectively is to index your tables - this way, uPortal queries will have to scan fewer records and set fewer locks - and this can speed up authentication into the portal tremendously. UP_USER, UP_USER_ATTS, ans UP_USER_PARM need to be indexed with a primary key - check out the documentation for your version of MySQL for the exact syntax.

Query Cache

You may be much better performance by enabling the MySQL query cache.

uPortal Configuration

Before using MySQL with uPortal, several uPortal properties files need to be altered for MySQL. These include:

build.properties

in your main uPortal "source" directory

rdbm.properties
PersonDirs.xml

both in /properties and POSSIBLY

dbloader.xml

in /properties/db.

In build.properties, the line about the jdbcDriver needs to point to the MySQL JDBC driver, as in:

jdbcDriver.jar=./lib/mysql-connector-java-3.1.8-bin.jar

(this is the /lib directory just beneath the "source" uPortal directory).

The uPortal rdbm.properties file will need to modified to specify the driver properties. First, comment out the property definitions which are currently defined (most likely, for HypersonicSQL). The rdbm.properties file contains several sample entries. Uncomment (or add) the lines for the MySQL database and make whatever changes necessary to match your local database installation, For example:

#MySQL Example
#jdbcDriver=org.gjt.mm.mysql.Driver
#the above is the format for older(pre-3.0) versions of the driver
jdbcDriver=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql://localhost/PortalDb
jdbcUser=<your PortalDb user>
jdbcPassword=<your PortalDb password>

The PersonDirs.xml file also needs to be modified; MySQL does not handle the "<uidquery>" element properly as it is written in the standard release. This file should be modified just before the start of the elements:

<!-- JDBC Properties -->
      <driver>com.mysql.jdbc.Driver</driver>
      <url>jdbc:mysql://localhost/PorttalDb</url>
      <logonid><your PortalDb user></logonid>
      <logonpassword><your PortalDb password></logonpassword>
      <uidquery>SELECT CONCAT_WS(' ',FIRST_NAME,LAST_NAME) AS FIRST_LAST,FIRST_NAME, LAST_NAME, EMAIL FROM UP_PERSON_DIR WHERE USER_NAME=?</uidquery>

or, the following 2 lines will work in 2.5.0+:

<res-ref-name>DEFAULT_DATABASE</res-ref-name>

      <uidquery>SELECT CONCAT_WS(' ',FIRST_NAME,LAST_NAME) AS FIRST_LAST, FIRST_NAME, LAST_NAME, EMAIL FROM UP_PERSON_DIR WHERE USER_NAME=?</uidquery>

Finally, the dbloader.xml properties file (also in the properties directory) may also need to be modified. This file is used by the DbLoader tool to create the uPortal database tables and populate the database. It contains several sample entries which create db-type-mappings for different databases. Find the tags for an MySQL database and modify the db-version, driver-name, and driver-version as necessary. For example:

<db-type-mapping>
      <db-name>MySQL</db-name>
      <db-version>4.1.10</db-version>
      <driver-name>Mark Matthews' driver</driver-name>
      <driver-version>3.1.8</driver-version>
      <type><generic>LONGVARCHAR</generic><local>TEXT</local></type>
      <!-- map more types here -->
    </db-type-mapping>

NOTE: this step isn't always necessary.

Once these modifications are done, you can deploy uPortal and have it use a MySQL database. "ant initportal", if build.properties is also set up to reflect the rest of your local configuration, should build the proper MySQL tables for you. A suggestion - before running the uPortal, verify that you can connect to your database outside of the portal with a utility like DB Visualizer (available at http://www.ming.se); this will confirm for you if you have any typos or other problems in getting a database connection.

When the MySQL tables are created, they will be the MySQL default type - as of this writing (5/23/05), that's MyISAM. These tables are NOT transaction safe, which means that if an error occurs, like a communications/network error, the tables cannot be rolled back to their previous state. There are places in the uPortal code where if such a problem occurs, the transaction is programmed to roll back to its previous state - but if the tables cannot accomodate this, an error about not being able to roll back the tables will be entered into portal.log, and the account will be unusable after that point. To avoid this, use transaction safe tables, which MySQL provides support for, in terms of either BDB (Berkeley database) or InnoDB tables. As of 4.0.5, support for InnoDB tables is included with MySQL; previous to that, it was an extra download.

Deadlock troubleshooting

One thing that will most likely come up in working with uPortal and MySQL (or any database for that matter) is the issue of deadlocks - when a record is needed to be accessed by two different queries at the same time. The MySQL site has an EXCELLENT chapter on dealing with these. Overall, the on-line reference guide for MySQL is an EXCELLENT resource.

uPortal_rel-2-6-0-RC2

1. Properties files that need to be altered include:

a) build.properties:
server.home=if using Tomcat replace with e.g. CATALINA_HOME

b) properties\rdbm.properties:
make whatever changes necessary to match your local database installation.

#MySQL Example
jdbcDriver=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql://localhost/PortalDb
jdbcUser=<your PortalDb user>
jdbcPassword=<your PortalDb password>

2. Download driver/connector:

http://dev.mysql.com/downloads/connector/j/5.0.html

>cp mysql-connector-java-5.0.6-bin.jar lib\container-common

3. Make sure that your MySQL instance is running:

cd "c:\Program Files\MySQL\MySQL Server 5.0\bin"

>mysql -u root -p

then enter your password when prompted. You should see something like the following:

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0-nt-max

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

4. Create database
>create database [name of database as in jdbcUrl];

5. Run ant task
>ant initportal

That's all you have to do to make uPortal work with MySQL.

Notes:
i) Make sure that mysql-connector-java-5.0.6-bin.jar is in server.home\common\lib
ii) Make sure that server.home\common\endorsed has serializer.jar and xalan-2.7.0.jar only.
iii) Make sure that server.home\shared\lib has pluto-1.0.1.jar and NOT pluto-1.0.1-rc2.jar.

Resources:
MySQL Basics - A Helpful MySQL Tutorial(http://www.analysisandsolutions.com/code/mybasic.htm)

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jul 28, 2005

    Bonnie Ferguson says:

    When using ant db to create the mySQL tables for uPortal 2.5, I got this error: ...

    When using ant db to create the mySQL tables for uPortal 2.5, I got this error:
    java.sql.SQLException: Specified key was too long; max key length is 1000 bytes
    when using ant db to create the mySQL tables UP_GROUP_MEMBERSHIP, UP_ENTITY_LOCK and UP_ENTITY_PROP - these each have composite keys (e.g. PRIMARY KEY (ENTITY_TYPE_ID, ENTITY_KEY, LOCK_OWNER, EXPIRATION_TIME)) which seem to exceed mySQL's limitation. Does anyone know of a good solution to this? Thanks!

    1. Aug 01, 2005

      Bonnie Ferguson says:

      This problem only occurs when the character encoding is set to UTF8, since this ...

      This problem only occurs when the character encoding is set to UTF8, since this uses 3 bytes for each character, thus exceeding the 1000 byte limit on these keys. By changing the encoding to Latin 1 when the database is created using :

      CREATE DATABASE db_name
      DEFAULT CHARACTER SET latin1

      this problem is solved. There is another possible solution that I saw on the mySQL site that could be used if you need to use UTF8 encoding. This uses only the first X characters of the longer fields for the key, as shown below:

      CREATE TABLE UP_GROUP_MEMBERSHIP
      (
      GROUP_ID VARCHAR(200) NOT NULL,
      MEMBER_SERVICE VARCHAR(80) NOT NULL,
      MEMBER_KEY VARCHAR(200) NOT NULL,
      MEMBER_IS_GROUP VARCHAR(1) NOT NULL,
      PRIMARY KEY (GROUP_ID(125), MEMBER_SERVICE, MEMBER_KEY(125), MEMBER_IS_GROUP)
      )

      This will index the first 125 chars from the 2 longer columns - making a total of 331 characters (331 * 3 = 993 bytes) which should work and be faster in general as well. I have not tried this solution though...

      thanks
      Bonnie

  2. Jun 27, 2007

    Dhafer says:

    \\ Helle \! When using ant dbtest to test the configuration of my data base I ha...


    Helle !

    When using ant dbtest to test the configuration of my data base I have got

    BUILD FAILED
    Target `dbtest' does not exist in this project.

    I have the same message when I do  ant db

    for the information I'm following this tutorial :

    http://esup-portail.org/consortium/espace/Formations/geneve/Manipulation%201%20Administration/

    do someone know how to solve the problem ?

    thanks in advance 

  3. Aug 22, 2007

    Sherwin Harris says:

    MySQL is case sensitive in Linux and not in Windows. Make sure that you have the...

    MySQL is case sensitive in Linux and not in Windows. Make sure that you have the lower_case_table_names=1 in the [mysqld] section of your my.cnf file. The case of the table names is being currently addressed but for now if you are trying to deploy uportal in linux, you will need to convert the table names to lower case. Here is a mysql sql script to do it:

    rename table UPC_PERM_MGR to upc_perm_mgr,UP_CHANNEL to up_channel,UP_CHANNEL_MDATA to up_channel_mdata,UP_CHANNEL_PARAM to up_channel_param,UP_CHAN_TYPE to up_chan_type,UP_CHAN_TYPE_MDATA to up_chan_type_mdata,UP_ENTITY_CACHE_INVALIDATION to up_entity_cache_invalidation,UP_ENTITY_LOCK to up_entity_lock,UP_ENTITY_PROP to up_entity_prop,UP_ENTITY_TYPE to up_entity_type,UP_FRAGMENTS to up_fragments,UP_FRAGMENT_PARAM to up_fragment_param,UP_FRAGMENT_RESTRICTIONS to up_fragment_restrictions,UP_GROUP to up_group,UP_GROUP_FRAGMENT to up_group_fragment,UP_GROUP_MEMBERSHIP to up_group_membership,UP_GROUP_PRIORITY_RANGE to up_group_priority_range,UP_LAYOUT_PARAM to up_layout_param,UP_LAYOUT_RESTRICTIONS to up_layout_restrictions,UP_LAYOUT_STRUCT to up_layout_struct,UP_LAYOUT_STRUCT_AGGR to up_layout_struct_aggr,UP_LAYOUT_STRUCT_LOCALE to up_layout_struct_locale,UP_LAYOUT_STRUCT_MDATA to up_layout_struct_mdata,UP_MIME_TYPE to up_mime_type,UP_OWNER_FRAGMENT to up_owner_fragment,UP_PERMISSION to up_permission,UP_PERSON_DIR to up_person_dir,UP_PORTLET_DEFINITION_PREFS to up_portlet_definition_prefs,UP_PORTLET_ENTITY_PREFS to up_portlet_entity_prefs,UP_PORTLET_PREF_VALUES to up_portlet_pref_values,UP_SEQUENCE to up_sequence,UP_SS_MAP to up_ss_map,UP_SS_STRUCT to up_ss_struct,UP_SS_STRUCT_PAR to up_ss_struct_par,UP_SS_THEME to up_ss_theme,UP_SS_THEME_PARM to up_ss_theme_parm,UP_SS_USER_ATTS to up_ss_user_atts,UP_SS_USER_PARM to up_ss_user_parm,UP_USER to up_user,UP_USER_LAYOUT to up_user_layout,UP_USER_LAYOUT_AGGR to up_user_layout_aggr,UP_USER_LAYOUT_MDATA to up_user_layout_mdata,UP_USER_LOCALE to up_user_locale,UP_USER_MDATA to up_user_mdata,UP_USER_PARAM to up_user_param,UP_USER_PROFILE to up_user_profile,UP_USER_PROFILE_LOCALE to up_user_profile_locale,UP_USER_PROFILE_MDATA to up_user_profile_mdata,UP_USER_UA_MAP to up_user_ua_map,UP_VERSIONS to up_versions;

    1. Aug 22, 2007

      Erik A. Olsson says:

      The other option here is to fix the one file that uses lowercase table names: RD...

      The other option here is to fix the one file that uses lowercase table names: RDBMDistributedLayoutStore.java

      See UP-1801 in JIRA for the corrected file.

    2. Aug 23, 2007

      Jason Shao says:

      I've edited the setup instructions to reflect the casesensitivity issue. I think...

      I've edited the setup instructions to reflect the case-sensitivity issue. I think after we get the conversion instructions polished up a bit (for Unix converts) we can just recommend lower_case_table_names as a best practice and clean up these notes.

  4. Aug 31, 2007

    Chris Wagner says:

    In releases where PersonDirs.xml is not used, the query in personDirectory.xml n...

    In releases where PersonDirs.xml is not used, the query in personDirectory.xml needs to be changed to the following:

    SELECT concat(concat(FIRST_NAME,' '),LAST_NAME) as FIRST_LAST, FIRST_NAME, LAST_NAME, EMAIL, USER_NAME FROM UP_PERSON_DIR WHERE USER_NAME=?

    A good sign that this was not done is if you see "Welcome 0" after you log in as a database user.

    1. Sep 01, 2007

      Jason Shao says:

      Seems odd to do this concat in the DB query esp. given the differing syntax. Won...

      Seems odd to do this concat in the DB query – esp. given the differing syntax. Wonder if we should refactor to have Java code do the concats