The steps for installing MySQL on all Unix types of operating systems are basically the same. This includes
Linux, Sun Solaris, FreeBSD, IBM AIX, HP-UX, etc. It’s recommended that
you install MySQL with a binary distribution, but as explained in the
previous section, sometimes you may want to use a source distribution. To
install a source distribution, you will need copies of GNU gunzip, GNU tar, GNU gcc (at least version 2.95.2), and
GNU make. These tools are usually included in all Linux
systems and in most Unix systems. If your system doesn’t have them, you
can download them from the GNU Project’s site (http://www.gnu.org).
Once you’ve chosen and downloaded the source distribution files for MySQL, enter the following commands as root from the directory where you want the source files stored:
groupadd mysql useradd -g mysql mysql tar xvfz /tmp/mysql-version.tar.gz cd mysql-version
The first command creates the user group mysql. The second creates the
system user mysql and adds it to the group
mysql at the same time. The next command uses the
tar utility (along with gunzip via
the z option) to unzip and unpack the source
distribution file you downloaded. You should replace the word
version with the version number—that is to say,
you should use the actual path and filename of the installation file that
you downloaded for the second argument of the tar
command. The last command changes to the directory created by
tar in the previous line. That directory contains the
files needed to configure MySQL.
This brings you to the next step, which is to configure the source files to prepare them for building the binary programs. This is where
you can add any special build requirements you may have. For instance, if
you want to change the default directory from where MySQL is installed, use the
--prefix option with a value set to equal the desired
directory. To set the Unix socket file’s path, you can use
--with-unix-socket-path. If you would like to use a
different character set from the default of
latin1, use --with-charset. Here
is an example of how you might configure MySQL with these particular
options before building the binary files:
./configure --prefix=/usr/local/mysql \
--with-unix-socket-path=/tmp \
--with-charset=latin2You can also enter this command on one line without the backslashes.
Several other configuration options are available. To get a complete and current listing of options permitted, enter the following from the command line:
./configure --help
You may also want to look at the latest online documentation for compiling MySQL at http://dev.mysql.com/doc/mysql/en/compilation_problems.html.
Once you’ve decided on any options that you want, run the
configure script with these options. It will take quite
a while to run, and it will display a great deal of information, which you
can ignore usually if it ends successfully. After the configure script finishes, the binaries
will need to be built and MySQL needs to be initialized. To do this, enter
the following:
make make install cd /usr/local/mysql ./scripts/mysql_install_db
The first command builds the binary programs. If it’s successful, you need to enter the second line to install the binary programs and related files in the appropriate directories. In the next line, you’re changing to the directory where MySQL was installed. If you configured MySQL to be installed in a different directory, you’ll have to use that one instead. The last command uses a script provided with the distribution to generate the initial privileges or grant tables.
All that remains now is to change the ownership of the MySQL programs and directories. You can do this by entering the following:
chown -R mysql /usr/local/mysql chgrp -R mysql /usr/local/mysql
The first command changes ownership of the MySQL directories and
programs to the mysql user. The second command changes
the group owner of the same directory and files to
mysql. These file paths may be different depending on
the version of MySQL you installed and whether you configured MySQL for
different paths.
With the programs installed and their file ownerships properly set, you can start MySQL. You can do this in several ways. To make sure that the daemon is restarted in the event that it crashes, enter the following from the command line:
/usr/local/mysql/bin/mysqld_safe &
This starts the mysqld_safe daemon, which will in turn start the MySQL server mysqld. If the mysqld daemon crashes, mysqld_safe will restart it. The ampersand at the end of the line instructs the shell to run the daemon in the background.
To have MySQL started at boot time, copy the mysql.server file, located in the support-files subdirectory of /usr/local/mysql, to the /etc/init.d directory. To do this, enter the following from the command line:
cp support-files/mysql.server /etc/init.d/mysql chmod +x /etc/init.d/mysql chkconfig --add mysql
The first line follows a convention of placing the startup file for the server in the server’s initial daemons directory with the name mysql. You should change the file paths to the equivalent directory on your system. The second command makes the file executable. The third sets the run level of the service for startup and shutdown.
Now that MySQL is installed and running, you need to make some postinstallation adjustments that are explained in the last section of this chapter (Postinstallation”).