3.4 Configuring MySQL on the LVM Logical Volume

MySQL databases are usually located in a subdirectory of the /var/lib/mysql/ directory. If you create a database named test, then the database files are located in the /var/lib/mysql/test directory.

In order for MySQL to take advantage of the benefits provided by Novell Cluster Services, you must make some configuration changes to MySQL. On the first server, you copy the default MySQL configuration file (/etc/my.cnf) to the LVM logical volume, modify /mnt/mysql/var/lib/mysql/my.cnf file so that all datadir entries are commented out, then create a MySQL database on the LVM Logical volume.

The following instructions assume that you have not created a database on the server at this time. If a MySQL database currently exists in the default /var/lib/mysql location, the database’s directory and its contents must be relocated to the new /mnt/mysql/var/lib/mysql path, rather than creating it as described in Step 6 of the following procedure. Afterwards, Ensure that you modify the ownership of the folder and files to the mysql user and group by using the chown command as illustrated in Step 13 of Section 3.3, Creating an LVM Volume Group and Logical Volume.

IMPORTANT:After you have modified the MySQL configuration file to use the LVM logical volume path, you should always exclusively activate the volume group on the server before attempting to start the MySQL daemon. The cluster resource does this automatically in the load script.

To configure a MySQL database on the LVM logical volume:

  1. Log in as the Linux root user on the first node, then open a file browser or terminal console.

  2. Copy the default /etc/my.cnf configuration file to the /mnt/mysql/var/lib/mysql directory. Enter

    cp /etc/my.cnf /mnt/mysql/var/lib/mysql
  3. In a text editor, modify the /mnt/mysql/var/lib/mysql/my.cnf file and comment out any data directory entries, then save your changes.

    # datadir= 
  4. Change the permissions on the /mnt/mysql/var/lib/mysql/my.cnf file to Read and Execute for each permission level, and change the ownership to the mysql user and group. Enter the following commands:

    chmod 555 /mnt/mysql/var/lib/mysql/my.cnf
    chown mysql:mysql /mnt/mysql/var/lib/mysql/my.cnf

    You can view these settings by using the ll <filepath> command. For example:

    ll /mnt/mysql/var/lib/mysql/my.cnf
      -r-xr-xr-x 1 mysql mysql 6297 2011-07-08 14:19 /mnt/mysql/var/lib/mysql/my.cnf
  5. Open a terminal console as the Linux root user, then start MySQL:

    /etc/init.d/mysql start

    Another option is to use the rcmysql start command.

  6. Create a database named data on the LVM logical volume:

    mysql_install_db --datadir=/mnt/mysql/var/lib/mysql/data --user=mysql
  7. Set the ownership of the data database to be the mysql user and group:

    chown -R mysql:mysql /mnt/mysql/var/lib/mysql/data
  8. Stop the MySQL daemon from running:

    /etc/init.d/mysql stop

    Another option is to use the rcmysql stop command.

  9. Deactivate the LVM volume group:

    vgchange -a n <vg_name>

    For example:

    vgchange -a n mysqlvg
  10. Continue with Section 3.5, Cluster-Enabling MySQL on the Logical Volume.