Related Documentation Download this Excerpt
PDF (US Ltr) - 279.8Kb
PDF (A4) - 280.2Kb
EPUB - 97.2Kb
HTML Download (TGZ) - 63.5Kb
HTML Download (Zip) - 79.7Kb

Building MySQL from Source  /  Installing MySQL Using a Standard Source Distribution

Chapter 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 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 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 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 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 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 Debugging and Porting MySQL.

    Run ./configure --help for a list of options. Chapter 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 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 Chapter 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 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 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 Postinstallation Setup and Testing.

User Comments
  Posted by Anoop Viswanath on July 2, 2014
Detailed instructions for compiling MySQL Server from source code on Linux.

This one worked for me.

It also fixes the following errors with Googlemock.
Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.
CMake Error: Problem with tar_extract_all(): Invalid argument
CMake Error: Problem extracting tar: /usr/src/mysql-5.6.19/source_downloads/

Thanks to the author.
  Posted by Shahriyar Rzayev on June 29, 2015
With MySQL 5.7.7-rc if you try to use mysql_install_db it will throw an error indicating that, this script is deprecated:

[root@centos7_vm mysql]# bin/mysql_install_db --user=mysql
2015-06-29 11:24:11 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2015-06-29 11:24:11 [ERROR] The data directory needs to be specified.

Also, if you initialized MySQL to different datadir rather than default:

[root@centos7_vm mysql]# bin/mysqld --initialize --user=mysql --datadir=/opt/mysql/datadir

And after try to use bin/mysql_ssl_rsa_setup:

[root@centos7_vm mysql]# bin/mysql_ssl_rsa_setup
2015-06-29 11:42:28 [ERROR] Failed to normalize the argument for --datadir: /var/lib/mysql

As a workaround try to specify --datadir with mysql_ssl_rsa_setup too:

[root@centos7_vm mysql]# bin/mysql_ssl_rsa_setup --datadir=/opt/mysql/datadir
OpenSSL 1.0.1e-fips 11 Feb 2013

Sign Up Login You must be logged in to post a comment.