Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

1. Shut down Tomcat

  1. Run bin/shutdown.sh or bin/shutdown.bat to bring Tomcat down while you are making these changes.
  2. Make a backup of your <tomcat-install>/conf/server.xml file so that you can easily revert if you have a problem.

...

These instructions will help you connect TermWeb to a MySQL database.

1. Configuring MySQL

MySQL should allow packet sizes at least the size of maximum file attachment size, by default 15000 KB.

The default max packet size is 1MB, and you can configure this in your MySQL configuration file by setting the property max_allowed_packet. See the MySQL manual for more information.

2. Create database

  1. Create the TermWeb database by opening a DOS prompt and enter the following:

    mysql -u root -p < createdb.sql

    This creates an empty database called termweb and a user termwebuser with password termwebpwd. The user name and password can be changed as desired. The user currently needs all permissions (except GRANT) in the database.

  2. Import the termweb.sql file to the database, by running the following at the DOS prompt:

    mysql -u termwebuser -ptermwebpwd termweb < termweb.sql

3. Copy the MySQL JDBC Driver to Tomcat

  1. Download the MySQL Connector/J JDBC driver from http://dev.mysql.com/downloads/connector/j/
  2. After unpacking the file you have downloaded, you will find a file called something like mysql-connector-java-5.1.18x-bin.jar.
  3. If you are running Tomcat 5.5, copy this file into the common/lib directory of your Tomcat installation. For Tomcat 6, copy the

    Copy the file into <tomcat-install>/lib.

3. Configure Tomcat

  1. If you are using the Confluence distribution, edit the conf/server.xml file in your Tomcat installation. If you are running your own Tomcat instance, edit the XML file where you declared the Confluence Context descriptor.
  2. If editing conf/server.xml, find the following lines:

     

    <Context path="" docBase="../confluence" debug="0" reloadable="true">
                        <!-- Logger is deprecated in Tomcat 5.5. Logging configuration for Confluence is specified in confluence/WEB-INF/classes/log4j.properties -->
  3. Within the Context tags, directly after the opening <Context.../> line, insert the DataSource Resourcetag:

     

    <Resource name="jdbc/confluence" auth="Container"

     

    Warning
    titlePlease note
    MySQL Connector/J v5.1.36 contains a bug which causes it not to work together with MySQL 5.0.x.

4. Configure a DataSource for TermWeb in Tomcat

  • The configuration properties for Tomcat's standard data source resource factory (org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory) are as follows:
    • driverClassName – Fully qualified Java class name of the JDBC driver to be used.
    • maxActive – The maximum number of active instances that can be allocated from this pool at the same time.
    • maxIdle – The maximum number of connections that can sit idle in this pool at the same time.
    • maxWait – The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception.
    • password – Database password to be passed to our JDBC driver.
    • url – Connection URL to be passed to our JDBC driver. (For backwards compatibility, the property driverName is also recognized.)
    • user – Database username to be passed to our JDBC driver.
    • validationQuery – SQL query that can be used by the pool to validate connections before they are returned to the application. If specified, this query MUST be an SQL SELECT statement that returns at least one row.

4. Configure the Confluence Web Application

  1. Edit confluence/WEB-INF/web.xml in your Confluence installation.
  2. Go to the end of the file and insert the following element just before </web-app>:

     

    <resource-ref>
            <description>Connection Pool</description>
            <res-ref-name>jdbc/confluence</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
        </resource-ref>

5. Configure Confluence

If you have not yet set up Confluence:

  1. Follow the steps in the Confluence Setup Guide
  2. In the Database Setup section, choose the "Datasource Connection" option.
  3. Set the JNDI name to java:comp/env/jdbc/confluence
  4. Set the Database dialect to MySQL.

If you are changing an existing Confluence installation over to using a Tomcat datasource:

  1. Find your ConfluenceHome directory (see: Confluence Home Directory if you don't know where it is).
  2. Edit the confluence.cfg.xml file
  3. Delete any line that contains a property that begins with hibernate.
  4. Insert the following at the start of the <properties>section.

     

    <property name="hibernate.setup"><![CDATA[true]]></property>
        <property name="hibernate.dialect"><![CDATA[net.sf.hibernate.dialect.MySQLDialect]]></property>
        <property name="hibernate.connection.datasource"><![CDATA[java:comp/env/jdbc/confluence]]></property>

6. Restart Confluence

...

  1. Edit <tomcat-install>/conf/context.xml.

  2. Within the Context tags, insert the DataSource Resource tag:

    <Resource name="jdbc/TermWebDS"
      auth="Container"
      type="javax.sql.DataSource"
             
      username="
    yourusername
    termwebuser"
             
      password="
    yourpassword
    termwebpwd"
             
      driverClassName="com.mysql.jdbc.Driver"
             
      url="jdbc:mysql://localhost
    :3306
    /
    confluence?
    termweb?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf8&amp;rewriteBatchedStatements=true"
             maxActive
      maxTotal="
    15
    20"  
             maxIdle
      maxIdle="10"
    minIdle="
    7
    2"
             defaultTransactionIsolation
      testWhileIdle="
    READ_COMMITTED
    true" 
             
      validationQuery="Select 1"/>

     

    • Replace the username and password parameters with the correct values for your database.
    • In the url parameter, replace the word 'confluence' with the name of the database your Confluence data will be stored in.
    • If you plan to use non-Latin characters, you will also need to add "&useUnicode=true&characterEncoding=utf8" on the end of the above URL. These options are not required for any database other than MySQL.
Notes
  • If switching from a direct JDBC connection to datasource, you can find the above details in your <CONFLUENCE_HOME>/confluence.cfg.xml file.

...


  1. If MySQL does not run on the same server as Tomcat, replace localhost in url with the name of the database server.
    If you named the database something else than termweb, replace termweb in url with your database name.
    Replace termwebuser and termwebpwd in url with your database user and password.

  2. Check Version specific upgrade notes for any actions needed for your TermWeb version.

Warning
titlePlease note

Changes in <tomcat-install>/conf/context.xml can cause Tomcat to restart automatically


Include Page
Tomcat Data Source Configuration Properties
Tomcat Data Source Configuration Properties

(tick) Congratulations, you now have TermWeb connected to your MySQL database.