Table of Contents
Before you proceed with the source installation, check first to see if our binary is available for your platform and if it will work for you. We put a lot of effort into making sure that our binaries are built with the best possible options.
You need the following tools to build and install MySQL from source:
GNU gunzip to uncompress the distribution.
A reasonable tar to unpack the distribution. GNU tar is known to work. Some tar implementations that come pre-installed with the operating system (for example, Sun tar) is known to have problems with long file names). In that case, you should install GNU tar first.
A working ANSI C++ compiler. gcc 2.95.2 or later, egcs 1.0.2 or later or egcs 2.91.66, SGI C++, and SunPro C++ are some of the compilers that are known to work. libg++ is not needed when using gcc. gcc 2.7.x has a bug that makes it impossible to compile some perfectly legal C++ files, such as sql/sql_base.cc. If you only have gcc 2.7.x, you must upgrade your gcc to be able to compile MySQL. gcc 2.8.1 is also known to have problems on some platforms, so it should be avoided if a new compiler exists for the platform.
gcc 2.95.2 or later is recommended when compiling MySQL Version 3.23.x.
A good make program. GNU make is always recommended and is sometimes required. If you have problems, we recommend trying GNU make 3.75 or newer.
If you are using a recent version of gcc, recent enough to understand the -fno-exceptions option, it is very important that you use it. Otherwise, you may compile a binary that crashes randomly. We also recommend that you use -felide-constructors and -fno-rtti along with -fno-exceptions. When in doubt, do the following:
CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors \ -fno-exceptions -fno-rtti" ./configure \ --prefix=/usr/local/mysql --enable-assembler \ --with-mysqld-ldflags=-all-static
On most systems this will give you a fast and stable binary.
If you run into problems, please always use mysqlbug when posting questions to a MySQL mailing list. Even if the problem isn't a bug, mysqlbug gathers system information that will help others solve your problem. By not using mysqlbug, you lessen the likelihood of getting a solution to your problem. You will find mysqlbug in the scripts directory after you unpack the distribution. See Bug reports.
The basic commands you must execute to install a MySQL source distribution are:
shell> groupadd mysql shell> useradd -g mysql mysql shell> gunzip < mysql-VERSION.tar.gz | tar -xvf - shell> cd mysql-VERSION shell> ./configure --prefix=/usr/local/mysql shell> make shell> make install shell> cp support-files/my-medium.cnf /etc/my.cnf shell> cd /usr/local/mysql shell> bin/mysql_install_db shell> chown -R root . shell> chown -R mysql var shell> chgrp -R mysql . shell> 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.
If you start from a source RPM, do the following:
shell> rpm --rebuild --clean MySQL-VERSION.src.rpm
This will make a binary RPM that you can install.
A more detailed description follows.
To install a source distribution, follow these steps, then proceed to Post-installation, for post-installation initialization and testing:
Add a user and group for mysqld to run as:
shell> groupadd mysql shell> 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. They may also be called adduser and addgroup. You may wish to call the user and group something else instead of mysql.
Pick the directory under which you want to unpack the distribution, and move into it.
Obtain a distribution file from one of the sites listed in Getting MySQL. MySQL source distributions are provided as compressed tar archives and have names like mysql-VERSION.tar.gz, where VERSION is a number like 5.0.0-alpha.
Unpack the distribution into the current directory:
shell> gunzip < /path/to/mysql-VERSION.tar.gz | tar xvf -
This command creates a directory named mysql-VERSION.
With GNU tar, no separate invocation of gunzip is necessary. You can use the following alternative command to uncompress and extract the distribution:
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
Change 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/mysql shell> make
When you run configure, you might want to specify some options. Run ./configure --help for a list of options. configure 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. Post the bug report using the mysqlbug script. See Bug reports.
If the compile fails, see Compilation problems, for help with a number of common problems.
Install the distribution:
shell> make install
If you want to set up an option file, use one of those present in the support-files directory as template. For example:
shell> cp support-files/my-medium.cnf /etc/my.cnf
You might need to run these commands as root.
If you want to configure support for InnoDB tables, you should edit the /etc/my.cnf file, remove the # character before the option lines that start with innodb_..., and modify the option values to be what you want. See Option files, and InnoDB start.
Change location into the installation directory:
shell> cd /usr/local/mysql
If you haven't installed MySQL before, you must create the MySQL grant tables:
shell> bin/mysql_install_db
Note that for MySQL versions older than Version 3.22.10, mysql_install_db left the server running after creating the grant tables. This is no longer true; you will need to restart the server after performing the remaining steps in this procedure.
Change ownership of binaries to root and ownership of the data directory to the user that you will run mysqld as. Assuming that you are located in the installation directory (/usr/local/mysql), the commands look like this:
shell> chown -R root . shell> chown -R mysql var shell> chgrp -R mysql .
The first command changes the owner attribute of the files to the root user. The second changes the owner attribute of the data directory to the mysql user. The third changes the group attribute to the mysql group.
If you would like 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 support-files/mysql.server script itself and in Automatic start.
You can set up new accounts using the bin/mysql_setpermission script if you install the DBI and DBD::mysql Perl modules. For instructions, see Perl support.
After everything has been installed, you should initialize and test your distribution using this command:
shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &
For versions of MySQL older than 4.0, substitute bin/safe_mysqld for bin/mysqld_safe in the command.
If that command fails immediately and prints mysqld ended, you can find some information in the file mysql-data-directory/'hostname'.err. The likely reason is that you already have another mysqld server running. See Multiple servers.
Now proceed to Post-installation.