start page | rating of books | rating of authors | reviews | copyrights

Book HomeManaging and Using MySQLSearch this book

2.2. Unix Installation

MySQL is available for a wide variety of Unix platforms. In this chapter, we go over the steps necessary to install binary and source distributions on Solaris and Linux. These can also be used as a general guide to installation on other operating systems, which should be very similar to our examples.

2.2.1. Binary (Tarball) Distributions

To install a binary distribution, you need the tar utility and the GNU gunzip utility. These tools are now a part of the standard distribution of many Unix systems.

WARNING: Solaris tar is known to have problems with some of the long filenames in the MySQL binary distribution. To unpack the binary distribution successfully on a Solaris system, you may need to obtain GNU gtar. A binary distribution version of this is available from http://www.mysql.com/downloads/os-solaris.html.

The binary distributions are all named using the following convention: mysql-version-os.tar.gz. The version placeholder is the version number of the software contained in the distribution. The os placeholder is the operating system for which the binary distribution is built. Binary distributions named mysql-max-version-os.tar.gz contain a version of MySQL compiled with support for transaction-safe tables.

Assume, for example, that we have chosen to install MySQL 3.23.40 on a Sun Solaris server. Also assume the distribution file mysql-3.23.40-sun-solaris2.7-sparc.tar.gz has been downloaded into the /tmp directory.

We recommend that you create a user and group for MySQL administration. This user should be used to run the mysql server and perform administrative tasks. It is possible to run the server as root, but this is not recommended.

The first step is to create a user to run the MySQL server. On Solaris and Linux, this can be done with the useradd and groupadd utilities. In our example, we create a user called mysql . In practice, you can choose any username you like. Typically, you will need to be the root user to successfully perform these tasks, so before anything else, use the su command to become root:

$ su - root
$ groupadd mysql
$ useradd -g mysql mysql

Select the desired location for the mysql software and change your current directory to that location. In this example, we install into /usr/local, which is the standard install location assumed by the MySQL software. You can, of course, install it wherever you like. If you choose an install location other than /usr/local, you will need to modify some of the scripts provided by MySQL. See the MySQL installation instructions at http://www.mysql.com/documentation for more details.

$ cd /usr/local

Now unpack the software:

$ gunzip -c /tmp/mysql-3.23.40-sun-solaris2.7-sparc.tar.gz | tar -xf -

Since we are installing on a Solaris server, the previous command may not work if GNU tar is installed as a separate version of tar. In this case, use the command:

$ gunzip -c /tmp/mysql-3.23.40-sun-solaris2.7-sparc.tar.gz | gtar -xf -

You should now see a new directory.

$ ls -ld mysql*
total 1
drwxr-xr-x  28 user  users  1024 Jul 18 14:29 mysql-3.23.40-sun-solaris2.7-sparc/

The next step is to create a symbolic link so that the installation can be referred to as /usr/local/mysql:

$ ln -s mysql-3.23.40-sun-solaris2.7-sparc mysql
$ ls -ld mysql* 
lrwxrwxrwx 1 user users 31  Jul 26 18:32 mysql -> mysql-3.23.40-sun-solaris2.7-sparc/
drwxr-xr-x 12 user users 1024 Jul 18 17:07 mysql-3.23.40-sun-solaris2.7-sparc/

Now, let's go into the mysql directory and have a look around:

$ cd mysql
$ ls -l
total 4476
-rw-r--r--   1 user     users       19076 Jul 18 14:21 COPYING
-rw-r--r--   1 user     users       28011 Jul 18 14:21 COPYING.LIB
-rw-r--r--   1 user     users      122213 Jul 18 14:19 ChangeLog
-rw-r--r--   1 user     users       14842 Jul 18 14:21 INSTALL-BINARY
-rw-r--r--   1 user     users        1976 Jul 18 14:19 README
drwxr-xr-x   2 user     users        1024 Jul 18 17:07 bin/
-rwxr-xr-x   1 user     users         773 Jul 18 17:07 configure*
drwxr-x---   4 user     users        1024 Jul 26 18:27 data/
drwxr-xr-x   2 user     users        1024 Jul 18 17:07 include/
drwxr-xr-x   2 user     users        1024 Jul 18 17:07 lib/
-rw-r--r--   1 user     users     2321255 Jul 18 14:21 manual.html
-rw-r--r--   1 user     users     1956858 Jul 18 14:21 manual.txt
-rw-r--r--   1 user     users       80487 Jul 18 14:21 manual_toc.html
drwxr-xr-x   6 user     users        1024 Jul 18 17:07 mysql-test/
drwxr-xr-x   2 user     users        1024 Jul 18 17:07 scripts/
drwxr-xr-x   3 user     users        1024 Jul 18 17:07 share/
drwxr-xr-x   7 user     users        1024 Jul 18 17:07 sql-bench/
drwxr-xr-x   2 user     users        1024 Jul 18 17:07 support-files/
drwxr-xr-x   2 user     users        1024 Jul 18 17:07 tests/ 

Although the software is now installed, we have a few set-up tasks left to do. Run scripts/mysql_install_db to create the MySQL grant tables:

$ scripts/mysql_install_db
Preparing db table
Preparing host table
Preparing user table
Preparing func table
Preparing tables_priv table
Preparing columns_priv table
Installing all prepared tables
010726 19:40:05  ./bin/mysqld: Shutdown Complete

Set up the ownership of the binaries so they are owned by root in the MySQL adminstrator group that you created earlier (in our case, mysql):

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

Set the ownership of the data directories to the MySQL administrative user you created earlier (for this example, mysql):

$ chown -R mysql /usr/local/mysql/data

MySQL is now installed and ready to go. To start the server, run safe_mysqld:

$ bin/safe_mysqld --user=mysql &

Typically, you will want to start up MySQL at server boot. To do this, you can copy support-files/mysql.server to the appropriate location on your system. This is covered in Chapter 5.

2.2.2. Binary (RPM) Distributions

The recommended way to install MySQL on an Intel Linux system is via RedHat Package Manager (RPM). Table 2-1 lists the files that comprise a full MySQL installation.

Table 2-1. The files in a full MySQL RPM distribution

Filename

Description

MySQL-version.i386.rpm

MySQL server software

MySQL-client-version.i386.rpm

MySQL client software

MySQL-bench-version.i386.rpm

MySQL tests and benchmarks; requires the Perl and msql-mysql RPMs

MySQL-devel-version.i386.rpm

Libraries and include files for compiling other MySQL clients

MySQL-shared-version.i386.rpm

MySQL client shared libraries

The procedure for installing an RPM distribution is simple. First, obtain the RPMs you wish to install. At a minimum, you should install the server and client software. Second, use the rpm utility to install the packages.

For this example, we assume that all the RPM packages for Version 3.23.40 on an Intel Linux system will be installed. Also, assume the following RPM files have been downloaded to /tmp:

Execute this sequence of commands to install them:

$ rpm -i /tmp/MySQL-3.23.40-1.i386.rpm
$ rpm -i /tmp/MySQL-client-3.23.40-1.i386.rpm
$ rpm -i /tmp/MySQL-devel-3.23.40-1.i386.rpm
$ rpm -i /tmp/MySQL-bench-3.23.40-1.i386.rpm
$ rpm -i /tmp/MySQL-shared-3.23.40-1.i386.rpm

The RPM creates the appropriate entries in /etc/rc.d to automatically start and stop the server at system boot and shutdown. The RPM also starts the mysql server, so after the RPM install is complete, you are ready to start using MySQL.

The RPM distributions place the files in different locations from the tarball distributions. To examine an RPM to determine where the files were placed, use the RPM query option:

$ rpm -qpl MySQL-version.i386.rpm

If you wish to determine the location but have discarded the RPM files already, you can query the RPM database:

$ rpm -ql MySQL-version

Also note that the RPM places data in /var/lib/data instead of /usr/local/mysql/data.

2.2.3. Source Distributions

Installing from a source distribution is different from installing a binary distribution. Since you will be building the software from source code, you will need a full set of tools, including:

Compiling from source is an intricate process with many possible variations depending upon your operating system, your desired configuration, your toolset, etc. As a result, we provide an overview of the process to get you started. However, we assume that you are experienced with building software from source. If you encounter problems building or installing MySQL, please refer to the full MySQL install documentation set at http://www.mysql.com/documentation.

The source distributions are named using the following convention: mysql-version.tar.gz. There is no special MySQL-Max version of the MySQL source, because all versions are compiled from the same code base.

For our example, assume that mysql-3.23.40.tar.gz has been downloaded to /tmp.

As with the binary install, the first step is to create a user who will run the MySQL server:

$ su - root
$ groupadd mysql
$ useradd -g mysql mysql

In your filesystem, move to the location where you would like to unpack the source. Unpack the bundle:

$ gunzip -c /tmp/mysql-3.23.40.tar.gz | tar -xf -

Move into the newly created mysql directory. You must configure and build MySQL from this location:

$ cd mysql-3.23.40

Now, use the configure script to configure your build. In this example, we use the prefix option to set the install location to /usr/local/mysql:

$ ./configure  --prefix=/usr/local/mysql

The configure utility offers a host of options that you can use to control how your build is set up. For more help on the available options, run:

$ ./configure  --help

Also, check the full install documentation at http://www.mysql.com/documentation for a list of common configure options.

The configure utility may take a few minutes to complete. Once it is done, it is time to build the binaries:

$ make

If all goes well, you now have a binary version of MySQL. The last thing you need to do is install it:

$ make install

The software is now installed. We have a few set-up tasks left to do. Run mysql_install_db to create the MySQL grant tables:

$ cd /usr/local/mysql
$ scripts/mysql_install_db
Preparing db table
Preparing host table
Preparing user table
Preparing func table
Preparing tables_priv table
Preparing columns_priv table
Installing all prepared tables
010726 19:40:05  ./bin/mysqld: Shutdown Complete

Set up the ownership of the binaries so they are owned by root and in the MySQL adminstrator group that you created earlier (in this case, mysql):

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

Set the ownership of the data directories to the MySQL administrative user you created earlier (for this example, mysql):

$ chown -R mysql /usr/local/mysql/data

MySQL is now installed and ready to go. To start the server, run safe_mysqld :

$ bin/safe_mysqld  --user=mysql &

Typically, you will want to start up MySQL at server boot. To do this, you can copy support-files/mysql.server to the appropriate location on your system. This is covered in greater detail in Chapter 5.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.