2.11.2 Installing MySQL Using a Standard Source Distribution

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.5.1, “Installing MySQL on Linux Using RPM Packages”.

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.2, “Installing MySQL on Unix/Linux Using Generic Binaries”. For a MySQL .tar.gz source distribution, the basic installation command sequence looks like this:

# Preconfiguration setup
shell> groupadd mysql
shell> useradd -g mysql -s /bin/false mysql
# Beginning of source-build specific instructions
shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> ./configure --prefix=/usr/local/mysql
shell> make
shell> make install
# End of source-build specific instructions
# Postinstallation setup
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql var
# Next command is optional
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

A more detailed version of the source-build specific instructions is shown following. Perform the following steps as the mysql user, except as noted.


The procedure shown here does not set up any passwords for MySQL accounts. After following the procedure, proceed to Section 2.12, “Postinstallation Setup and Testing”, for postinstallation setup and testing.

  1. Set up the mysql user and group that will be used to run and execute the MySQL server and own the database directory. For details, see Creating a mysql System User and Group, in Section 2.2, “Installing MySQL on Unix/Linux Using Generic Binaries”.

  2. Pick the directory under which you want to unpack the distribution and change location into it.

  3. Obtain a distribution file using the instructions in Section 2.1.2, “How to Get MySQL”.

  4. 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 -
  5. Change location into the top-level directory of the unpacked distribution:

    shell> cd mysql-VERSION
  6. Configure the source directory:

    shell> ./configure --prefix=/usr/local/mysql

    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 Section 22.4, “Debugging and Porting MySQL”.

    Run ./configure --help for a list of options. Section 2.11.4, “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.7, “How to Report Bugs or Problems”.

  7. Compile the source distribution:

    shell> make

    Use gmake instead on systems where you are using GNU make and it has been installed as gmake.

    If the compile fails, see Section 2.11.5, “Dealing with Problems Compiling MySQL”, for help.

  8. Install the distribution:

    shell> make install

    You might need to run this command as root.

The remainder of the installation process, including setting up the configuration file, creating the core databases, and starting the MySQL server, are identical to the remainder of the process as shown in Generic Binary Install.

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 &

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 host_name.err file in the data directory).

For more information about mysqld_safe, see 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.10, “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.12, “Postinstallation Setup and Testing”.