
#include "bacula_template.inc" title="Installing and Configuring MySQL" num=25

<H1>Installing and Configuring MySQL</H1>

<h2>Installing and Configuring MySQL -- Phase I</h2>
If you use the ./configure --with-mysql=mysql-directory statement
for configuring <b>Bacula</b>, you will need MySQL version 3.23.33
or later installed in the <b>mysql-directory</b> (we are
currently using 3.23.56). If MySQL is 
installed in the standard system location, you need only enter
<b>--with-mysql</b> since the configure program will search 
all the standard locations. If you install MySQL in your home
directory or some other non-standard directory, you will need
to provide the full path to it.

<p>Installing and Configuring MySQL is not difficult but can
be confusing the first time. As a consequence, below, we list
the steps that we used to install it on our machines. Please note
that our configuration leaves MySQL without any user passwords.
This may be an undesirable situation if you have other users
on your system.
<p>
Please note that as of Bacula version 1.31, the thread safe version
of the MySQL client library is used, and hence you must add the
<b>--enable-thread-safe-client</b> option to the <b>./configure</b>
as shown below:

<p>
<ol type="1">
    <li>Download MySQL source code from <a
         href="http://www.mysql.com/downloads">www.mysql.com/downloads</a>
        <p>
        <li>Detar it with something like:<p></p>
        <b>tar xvfz mysql-filename</b>
        <p>Note, the above command requires GNU tar. If you do not
        have GNU tar, a command such as:<p>
        <b>zcat mysql-filename | tar xvf -</b><p>
        will probably accomplish the same thing. </li>
        <p>
        <li>cd <b>mysql-source-directory</b><p></p>
        where you replace <b>mysql-source-directory</b> with the
        directory name where you put the MySQL source code.</li>
        <p>
        <li>./configure --enable-thread-safe-client --prefix=mysql-directory<p></p>
        where you replace <b>mysql-directory</b> with the directory
        name where you want to install mysql. Normally for system
        wide use this is /usr/local/mysql. In my case, I use
        ~kern/mysql.</li>
        <p>
        <li>make<p></p>
        This takes a bit of time.</li>
        <p>
        <li>make install<p></p>
        This will put all the necessary binaries, libraries and support
        files into the <b>mysql-directory</b> that you specified above.</li>
        <p>
        <li>./scripts/mysql_install_db<p></p>
        This will create the necessary MySQL databases for controlling
        user access. Note, this script can also be found in the
        <b>bin</b> directory in the installation directory </li>
        <p>

</ol>
The MySQL client library <b>mysqlclient</b> requires the gzip
compression library <b>libz.a</b> or <b>libz.so</b>. If you are
using rpm packages, these libraries are in the <b>libz-devel</b>
package. On Debian systems, you will need to load the <b>zlib1g-dev</b>
package. If you are not using rpms or debs, you will need to find the
appropriate package for your system.
<p>
At this point, you should return to completing the installation
of <b>Bacula</b>. Later after Bacula is installed, come
back to this chapter to complete the installation. Please note,
the installation files used in the second phase of the MySQL 
installation are created during the Bacula Installation.

<a name="mysql_phase2"></a>
<h2>Installing and Configuring MySQL -- Phase II</h2>
At this point, you should have built and installed MySQL, or
already have a running MySQL, and you should have configured,
built and installed <b>Bacula</b>. If not, please complete these
items before proceeding.  

<p>Please note that the <b>./configure</b> used to build
<b>Bacula</b> will need to include <b>--with-mysql=mysql-directory</b>,
where <b>mysql-directory</b> is the directory name that you specified
on the ./configure command for configuring MySQL. This is needed
so that Bacula can find the necessary include headers and
library files for interfacing to MySQL.

<p>
<b>Bacula</b> will install scripts for manipulating the database (create, delete, 
make tables etc) into the main installation directory.  These files
will be of the form *_bacula_* (e.g. create_bacula_database).  These files are
also available in the &lt;bacula-src&gt;/src/cats directory after running
./configure.  If you inspect create_bacula_database, you will see that it calls
create_mysql_database.  The *_bacula_* files are provided for convenience.
It doesn't matter what database you have chosen; create_bacula_database will
always create your database.

<p>
Now you will create the Bacula MySQL database and the
tables that Bacula uses.
<p>
<ol type="1">
  <li>Start <b>mysql</b>. You might want to use the <b>startmysql</b>
     script provided in the Bacula release.</li>
  <li>cd &lt;install-directory&gt;<p></p>
     This directory contains the Bacula catalog 
     interface routines.</li>
     <p>
  <li>./grant_mysql_privileges<p></p>
     This script creates unrestricted access rights for
     <b>kern</b>, <b>kelvin</b>, and <b>bacula</b>. You may
     want to modify it to suit your situation. Please note that
     none of these userids including root are password protected.</li>
     <p>
  <li>./create_mysql_database<p></p>
     This script creates the MySQL <b>bacula</b> database.  
     The databases you create as well as the access databases
     will be located in &lt;install-dir&gt;/var/ in a subdirectory
     with the name of the database, where &lt;install-dir&gt; is the
     directory name that you specified on the <b>--prefix</b> option. This
     can be important to know if you want to make a special backup
     of the Bacula database or to check its size.</li>
     <p>
  <li>./make_mysql_tables<p></p>
     This script creates the MySQL tables used by <b>Bacula</b>.</li>
</ol>
<p></p>
Each of the three scripts (grant_mysql_privileges, create_mysql_database
and make_mysql_tables) allows the addition of a command line
argument. This can be useful for specifying the user and or
password.  For example, you might need to add <b>-u root</b>
to the command line to have sufficient privilege to create
the Bacula tables.
<p>
To take a closer look at the access privileges that you have
setup with the above, you can do:
<pre>
mysql-directory/bin/mysql -u root mysql<br>
select * from user;
</pre>

<h2>Re-initializing the Catalog Database</h2>
After you have done some initial testing with <b>Bacula</b>, 
you will probably want to re-initialize the catalog database
and throw away all the test Jobs that you ran.
To do so, you can do the following:
<pre>
  cd &lt;install-directory&gt;
  ./drop_mysql_tables
  ./make_mysql_tables
</pre>
Please note that all information in the database will be
lost and you will be starting from scratch. If you have
written on any Volumes, you must write and end of file
mark on the volume so that Bacula can reuse it.
Do so with:
<pre>
   (stop Bacula or unmount the drive)
   mt -f /dev/nst0 rewind
   mt -f /dev/nst0 weof
</pre>

Where you should replace <b>/dev/nst0</b> with the
appropriate tape drive device name for your machine.


<h2>Linking Bacula with MySQL</h2>
After configuring Bacula with
<p class="tty">./configure --enable-thread-safe-client --prefix=&lt;mysql-directory&gt;</p>
where &lt;mysql-directory&gt; is in my case <b>/home/kern/mysql</b>,
you may have to configure the loader so that it can find the
MySQL shared libraries. If you have previously followed this procedure
and later add the <b>--enable-thread-safe-client</b> options, you
will need to rerun the <b>ldconfig</b> program shown below.
If you put MySQL in a standard place such
as <b>/usr/lib</b> or <b>/usr/local/lib</b> this will not be necessary,
but in my case it is. The description that follows is Linux specific.
For other operating systems, please consult your manuals on
how to do the same thing:
<p>First edit: <b>/etc/ld.so.conf</b> and add a new line to the
end of the file with the name of the mysql-directory.  In my case,
it is:
<p class="tty">/home/kern/mysql/lib/mysql</p>
then rebuild the loader's cache with:
<p class="tty">/sbin/ldconfig</p>
If you upgrade to a new version of <b>MySQL</b>, the shared library
names will probably changes, and you must re-run the
<b>/sbin/ldconfig</b> command so that the runtime loader can
find them.
<p>Alternatively, your system my have a loader environment
variable that can be set. For example, on a Solaris system
where I do not have root permission, I use:
<p class="tty">LD_LIBRARY_PATH=/home/kern/mysql/lib/mysql</p>
<p>Finally, if you have encryption enabled in MySQL, you may need to
explicitly edit the Makefile in several of the directories to add
<b>-lssl -lcrypto</b> to the link.

<page_prev name="The Bootstrap File Format" url="bootstrap.html">
<page_next name="Installing and Configuring PostgreSQL" url="postgresql.html">
