http:// / scripts / rules / mysql.shtml

Setting up a MySQL database

This page documents how to set up a MySQL database for use with the qmail rules interface.

Installing MySQL

MySQL is usually included in the operating system's repositories. If this is the case, you should install it from there, so that the server can be upgraded easily when security issues are found.

For example, under the RedHat-flavoured distributions (i.e. RedHat Enterprise, Fedora, CentOS, etc.) you can run a command like this to install the server:

# yum install mysql-server

The specific package name may vary, but the procedure should be very similar.

If your system doesn't have a package repository from which to install the software, you can always install it from the source code.

After installing the software, make sure the server is running, and that your system is configured to automatically start the server when the machine boots up.

Creating the database and users

Note that you should already have downloaded the files and run the ./ script.

To set up the database using MySQL, do the following:

Once this is done, the database will be ready for the web interface to be used to start creating rules.

The Perl DBD::mysql Module

In order for Perl to connect to a MySQL database, you need to make sure that the DBD::mysql module is installed correctly.

On a RedHat/CentOS system, you can install it as an OS package, using this command:

# yum install perl-DBD-mysql

Other operating systems may have similar OS packages available. If all else fails, you can always install it from CPAN:

# perl -MCPAN -e install DBD::mysql

Building the module from source like this will require that you have the MySQL developer packages installed on your system.

The G4DBCONN Value

When configuring the web interface and the mail script, you will need to set the value of the G4DBCONN environment variable. For a MySQL database, the value needs to look like this:

SetEnv G4DBCONN "dbi:mysql:database=rules"

If the database is physically stored on a different machine, you may need to include parameters which specify the hostname and/or port number. If so, the value will look like this:

SetEnv G4DBCONN "dbi:mysql:database=rules;host=HOST;port=PORT"