To install MySQL from source, first configure, build, and install from a source package. Then follow the same postinstallation setup sequence as for a binary installation.
If you start from a source RPM, use the following command to make a binary RPM that you can install. If you do not have rpmbuild, use rpm instead.
shell> rpmbuild --rebuild --clean MySQL-VERSION.src.rpm
The result is one or more binary RPM packages that you install as indicated in Section 2.4, “Installing MySQL from RPM Packages on Linux”.
The sequence for installation from a compressed
tar file source distribution is similar to the
process for installing from a generic binary distribution that is
detailed in Section 2.8, “Installing MySQL from Generic Binaries on Other Unix-Like Systems”. For a MySQL
.tar.gz source distribution, the basic
installation command sequence looks like this:
# Preconfiguration setup shell>groupadd mysqlshell>useradd -g mysql mysql# Beginning of source-build specific instructions shell>tar zxvf mysql-shell>VERSION.tar.gzcd mysql-shell>VERSION./configure --prefix=/usr/local/mysqlshell>makeshell>make install# End of source-build specific instructions # Postinstallation setup shell>cp support-files/my-medium.cnf /etc/my.cnfshell>cd /usr/local/mysqlshell>chown -R mysql .shell>chgrp -R mysql .shell>bin/mysql_install_db --user=mysqlshell>chown -R root .shell>chown -R mysql varshell>bin/mysqld_safe --user=mysql &
For versions of MySQL older than 4.0, substitute bin/safe_mysqld for bin/mysqld_safe in the final command.
This procedure does not set up any passwords for MySQL accounts. After following the procedure, proceed to Section 2.10, “Postinstallation Setup and Testing”, for postinstallation setup and testing.
A more detailed version of the preceding description for installing MySQL from a source distribution follows:
Add a login user and group for mysqld to run as:
shell>groupadd mysqlshell>useradd -g mysql mysql
These commands add the mysql group and the
mysql user. The syntax for
useradd and groupadd may
differ slightly on different versions of Unix, or they may
have different names such as adduser and
addgroup.
You might want to call the user and group something else
instead of mysql. If so, substitute the
appropriate name in the following steps.
Perform the following steps as the mysql
user, except as noted.
Pick the directory under which you want to unpack the distribution and change location into it.
Obtain a distribution file using the instructions in Section 2.1.3, “How to Get MySQL”.
Unpack the distribution into the current directory.
tar can uncompress and unpack the
distribution if it has z option support:
shell> tar zxvf /path/to/mysql-VERSION.tar.gz
This command creates a directory named
mysql-.
VERSION
If your tar does not have
z option support, use
gunzip to unpack the distribution and
tar to unpack it:
shell> gunzip < /path/to/mysql-VERSION.tar.gz | tar xvf -
Change location into the top-level directory of the unpacked distribution:
shell> cd mysql-VERSION
Note that currently you must configure and build MySQL from this top-level directory. You cannot build it in a different directory.
Configure the release and compile everything:
shell>./configure --prefix=/usr/local/mysqlshell>make
When you run configure, you might want to
specify other options. For example, if you need to debug
mysqld or a MySQL client, run
configure with the
--with-debug option, and
then recompile and link your clients with the new client
library. See
MySQL
Internals: Porting.
Run ./configure --help for a list of options. Section 2.9.3, “MySQL Source-Configuration Options”, discusses some of the more useful options.
If configure fails and you are going to
send mail to a MySQL mailing list to ask for assistance,
please include any lines from config.log
that you think can help solve the problem. Also include the
last couple of lines of output from
configure. To file a bug report, please use
the instructions in Section 1.8, “How to Report Bugs or Problems”.
If the compile fails, see Section 2.9.4, “Dealing with Problems Compiling MySQL”, for help.
Install the distribution:
shell> make install
You might need to run this command as root.
If you want to set up an option file, use one of those present
in the support-files directory as a
template. For example:
shell> cp support-files/my-medium.cnf /etc/my.cnf
You might need to run this command as root.
If you want to configure support for InnoDB
tables, you should edit the /etc/my.cnf
file, removing the # character before the
option lines that start with innodb_...,
and modify the option values to be what you want. See
Section 4.2.3.3, “Using Option Files”, and
Section 13.2.3, “InnoDB Configuration”.
Change location into the installation directory:
shell> cd /usr/local/mysql
If you ran the make install command as
root, the installed files will be owned by
root. Ensure that the installation is
accessible to mysql by executing the
following commands as root in the
installation directory:
shell>chown -R mysql .shell>chgrp -R mysql .
The first command changes the owner attribute of the files to
the mysql user. The second changes the
group attribute to the mysql group.
If you have not installed MySQL before, you must create the MySQL data directory and initialize the grant tables:
shell> bin/mysql_install_db --user=mysql
If you run the command as root, include the
--user option as shown. If you run the
command while logged in as mysql, you can
omit the --user option.
The command should create the data directory and its contents
with mysql as the owner.
Note that for MySQL versions older than 3.22.10, mysql_install_db left the server running after creating the grant tables. This is no longer true; you need to restart the server after performing the remaining steps in this procedure.
Most of the MySQL installation can be owned by
root if you like. The exception is that the
data directory must be owned by mysql. To
accomplish this, run the following commands as
root in the installation directory:
shell>chown -R root .shell>chown -R mysql var
If the plugin directory is writable by the server, it may be
possible for a user to write executable code to a file in the
directory using SELECT
... INTO DUMPFILE. This can be prevented by making
plugin_dir read only to the
server.
If you want MySQL to start automatically when you boot your
machine, you can copy
support-files/mysql.server to the
location where your system has its startup files. More
information can be found in the script itself, and in
Section 2.10.2.2, “Starting and Stopping MySQL Automatically”.
You can set up new accounts using the
bin/mysql_setpermission script if you
install the DBI and
DBD::mysql Perl modules. See
Section 4.6.15, “mysql_setpermission — Interactively Set Permissions in Grant
Tables”. For Perl module
installation instructions, see Section 2.14, “Perl Installation Notes”.
After everything has been installed, test the distribution. To start the MySQL server, use the following command:
shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &
For versions of MySQL older than 4.0, substitute safe_mysqld for mysqld_safe in the command.
If you run the command as root, you should use
the --user option as shown. The option value is
the name of the login account that you created in the first step
to use for running the server. If you run the
mysqld_safe command while logged in as that
user, you can omit the --user option.
If the command fails immediately and prints mysqld
ended, look for information in the error log (which by
default is the
file
in the data directory).
host_name.err
More information about mysqld_safe is given in Section 4.3.2, “mysqld_safe — MySQL Server Startup Script”.
To make it more convenient to invoke programs installed in
/usr/local/mysql/bin, you can add that
directory to your PATH environment variable
setting. That enables you to run a program by typing only its
name, not its entire path name. See
Section 4.2.4, “Setting Environment Variables”.
The accounts that are listed in the MySQL grant tables initially have no passwords. After starting the server, you should set up passwords for them using the instructions in Section 2.10, “Postinstallation Setup and Testing”.

User Comments
Add your own comment.