Site News
Spammer domain block list updated [more]
OSX Killer apps collections updated [more]
 Automatic web page date stamping project [more]
 Basic Perl DBI tutorial [more]

Other Stuff
Farscape returns in 4 hour mini series [more]
Want to take back the internet, [Get Firefox!]
July 05, 2008


DISCLAIMER: All the information contained in this page, or any linked from it, is provided as is, having no warranty or support of any kind, and is used entirely at your own risk.

Basic MySQL Build, Install and Configuration


There seems no end to the number of times I am asked for help with building MySQL from source, so in order to make my life easier, I have finally found the time to write a tutorial, based in part on the information from the various readme files that are part of the source distribution, plus extracts from the documentation.

I start with creation of the daemon user (The actual server runs as this user), then build the server from source, then move onto post install configuration and testing, then finally detail how to start the server automatically on bootup, with examples for both Slackware and Redhat.

Requirements

Before starting out, you need to have a working gcc compiler, which is normally included with your Linux distribution, although its possible its not installed by default, you will need to check for its presence. One quick way to do this is to open a terminal (assuming you are in X Windows), and run the following command.

gcc -v

Which on my Slackware machine gives this result.

Reading specs from /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/specs
gcc version 2.95.3 20010315 (release)

If you get something like the above message, take a note of the version number, as you will need it later. On the other hand if you set something like this.

command not found

Then you guessed it, you don't have gcc installed, and need to check your distributions documentation for installation help.

After the compiler, you need the actual MySQL source code distribution (known as a tarball), this you can get from the main download page, or any of the mirrors it lists.

Starting

Now that you have confirmed you have a working gcc compiler, and downloaded the MySQL source, its time to move onto the actual installation, which is broken up into several steps, which you DO NEED TO work through in order, or you are going to end up in trouble.

So now log in as the root user, and start with Step 1.

Step 1. Creating the MySQL user and group

The first thing you need to do, yes even before you uncompress the source tarball, is to create the user, and group that the actual MySQL server will run as. You do this with the following commands.

groupadd mysqluseradd -g mysql mysql

These commands will add a new group called mysql, and then add a new user also named mysql into this new group.

Step 2. Compiling the server

Now that the user and group have been created, its time to build the server from the source that you downloaded earlier. But before starting comes the gotcha, which is the version of gcc thats supplied with some Linux distributions, such as Redhat 7.1 and Mandrake 8. These distributions use gcc 2.96, which is known to cause problems with compiling some apps, and yes MySQL is one of them with possible issues. That said I strongly recommend that you use gcc 2.95-3 or 3.3 which has none of these problems.

Remember when you worked through the requirements section, you noted the gcc version you had, well nows the time to use that information. So if your version if bad, then its up to you whether you continue or update before moving on.

That said, and understood, now we uncompress the source tarball like this.

tar xvfz mysql-3.23.49.tar.gz
TIP: For help with handling compressed files under Linux/Unix/OSX see my HOWTO, which covers most of the common formats in detail.

This will extract the source into the mysql-3.23.49, now change into this directory like this.

cd mysql-3.23.49

Now the source is decompressed, its time to configure the source for your system, which you do with the following command.

./configure --enable-thread-safe-client --prefix=/usr/local/mysql

The two parameters used, --enable-thread-safe-client does just as its name suggests, build the client in a way thats thread safe, and in this case its optional (I have a SMP box some do this with everything). The second --prefix=/usr/local/mysql sets the installation location. When this finishes, run the following commands to compile and install the server.

make
make install

Thats it, the end of the compilation, but not the end of the installation. Now you need to run the installation script, which you do with the following command.

scripts/mysql_install_db

This script will create the tables, needed for correct server function.

Step 3. Post Installation

At this point you have the server installed, but its not quite yet ready for use. Before you can start it you need to set specific permissions on the installation directories and files. Which you do with the following commands.

chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql

This will change the ownership to the root user, for all the files and directories under the /usr/local/mysql directory, then change the ownership to the mysql user for everything under /usr/local/mysql/var. Finally the group settings for everything under /usr/local/mysql to the mysql group you created earlier.

Now you need to copy the default configuration file to your /etc/ directory, which you do with the following command.

cp support-files/my-medium.cnf /etc/my.cnf

Step 4. Starting and Testing the server

At this point you have built, install and configured the server, so now its time to start and test it, which is done with the following command.

/usr/local/mysql/bin/safe_mysqld --user=mysql &

Which is all is well, gives the following message.

Starting mysqld daemon with databases from /usr/local/mysql/var

Just press Enter to return to the command prompt, and yes the server is still running in the background. Now its always a good move to make sure that the server is alive, which you do with the following command.

/usr/local/mysql/bin/mysqladmin ping

If the server is up and alive, it should respond with the following message.

mysqld is alive

If you do not get this, you need to go back and check each of the steps you followed to get to this point, looking for things like typos etc.

Step 5. Starting the server at bootup

Its usual to have MySQL start each time you bootup, which is covered in this section. How you do with depends on your Linux distribution. The following examples are for Slackware and Redhat.

Redhat
Starting MySQL on startup under Redhat is quite straightforward. It uses a the same startup script from the MySQL distribution as does Slackware. The First thing you need to do is copy this script to the startup scripts directory, which you do with the following command.

cp support-files/mysql.server /etc/rc.d/init.d

Now you need to make this script executable, which you do with the following command.

chmod +x /etc/rc.d/init.d/mysql.server

Finally you need to create a symbolic link to this script, so that it will be executed on bootup. For this there are two possible locations, depending on whether you boot directly into X windows or to the console, as I do. So starting with the console, you create the link with the following command.

ln -s /etc/rc.d/init.d/mysql.server /etc/rc.d/rc3.d/S98mysql

Now that was for those of us who boot to the command line. Now comes the link creation for those who boot to X windows, which you do with the following command.

ln -s /etc/rc.d/init.d/mysql.server /etc/rc.d/rc5.d/S98mysql

Slackware
Starting MySQL on bootup under Slackware is very simple, it even uses the same script as Redhat. Now unlike the previous example, this one works regardless of how you boot. As with the Redhat example you first need to copy the script to the startup script directory, which is done like this.

cp support-files/mysql.server /etc/rc.d

Just as with the Redhat example you need to make this script executable, which you do with the following command.

chmod +x /etc/rc.d/mysql.server

Now you need to edit your /etc/rc.d/rc.local file and add the following line to the end.

/etc/rc.d/mysql.server start
 
Updated: June 19, 2004 Top