Search the MySQL manual:

2.3.1 Quick Installation Overview

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> scripts/mysql_install_db
shell> chown -R root  /usr/local/mysql
shell> chown -R mysql /usr/local/mysql/var
shell> chgrp -R mysql /usr/local/mysql
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &

If your version of MySQL is older than 4.0, use safe_mysqld rather than mysqld_safe.

If you want to have support for InnoDB tables, you should edit the /etc/my.cnf file and remove the # character before the parameter that starts with innodb_.... See section 4.1.2 `my.cnf' Option Files, and section 7.5.3 InnoDB Startup Options.

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.

You can add new users using the bin/mysql_setpermission script if you install the DBI and DBD-mysql Perl modules.

A more detailed description follows.

To install a source distribution, follow these steps, then proceed to section 2.4 Post-installation Setup and Testing, for post-installation initialisation and testing:

  1. Pick the directory under which you want to unpack the distribution, and move into it.
  2. Obtain a distribution file from one of the sites listed in section 2.2.1 How to Get MySQL.
  3. If you are interested in using Berkeley DB tables with MySQL, you will need to obtain a patched version of the Berkeley DB source code. Please read the chapter on Berkeley DB tables before proceeding. See section 7.6 BDB or BerkeleyDB Tables. MySQL source distributions are provided as compressed tar archives and have names like `mysql-VERSION.tar.gz', where VERSION is a number like 4.1.1-alpha.
  4. 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.
  5. 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'.
  6. 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.
  7. 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. section 2.3.3 Typical configure Options, discusses some of the more useful options. If configure fails, and you are going to send mail to mysql@lists.mysql.com 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 if configure aborts. Post the bug report using the mysqlbug script. See section 1.7.1.3 How to Report Bugs or Problems. If the compile fails, see section 2.3.5 Problems Compiling MySQL?, for help with a number of common problems.
  8. Install everything:
    shell> make install
    
    You might need to run this command as root.
  9. Create the MySQL grant tables (necessary only if you haven't installed MySQL before):
    shell> scripts/mysql_install_db
    
    Note that MySQL versions older than Version 3.22.10 started the MySQL server when you run mysql_install_db. This is no longer true.
  10. Change ownership of binaries to root and ownership of the data directory to the user that you will run mysqld as:
    shell> chown -R root  /usr/local/mysql
    shell> chown -R mysql /usr/local/mysql/var
    shell> chgrp -R mysql /usr/local/mysql
    
    The first command changes the owner attribute of the files to the root user, the second one changes the owner attribute of the data directory to the mysql user, and the third one changes the group attribute to the mysql group.
  11. If you want to install support for the Perl DBI/DBD interface, see section 2.7 Perl Installation Comments.
  12. 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 section 2.4.3 Starting and Stopping MySQL Automatically.

After everything has been installed, you should initialise and test your distribution:

shell> /usr/local/mysql/bin/mysqld_safe --user=mysql &

If that command fails immediately with mysqld daemon 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 section 4.1.3 Running Multiple MySQL Servers on the Same Machine.

Now proceed to section 2.4 Post-installation Setup and Testing.

User Comments

Posted by Matt Juszczak on Saturday June 8 2002, @3:13pm[Delete] [Edit]

If you forget to do --prefix=/usr/local/mysql
during configure, your distribution will install
into /usr/local. Rerunning configure with the --
prefix=/usr/local/mysql seemed to make the
installation go into /usr/local/mysql, but the
script "mysql_install_db", etc...seemed to
require the --basedir argument, and SQL wouldn't
start. So if you forget to do --
prefix=/usr/local/mysql, clear out all configure
logs/caches before rerunning ./configure.

Posted by [name withheld] on Wednesday November 20 2002, @4:12am[Delete] [Edit]

Could the first two steps be omitted?If I 'm not a
system administrator,could I install MYSQL into
my own directory successfully?Thanks!

Posted by Matt Gregory on Thursday March 13 2003, @8:36am[Delete] [Edit]

Before following Mr. Juszczak's suggestion above I suggest that you do the following...

If you realize that you did not add the --prefix argument, then you may simply continue without changing anything. /usr/local is a perfectly acceptable place to install mysql. If you would rather do things *exactly* by the book, then before you go back and reconfigure as he suggests, do the following (make sure you are in the mysql src directory and logged in as root (or using sudo) first):
<pre>
make uninstall
make distclean
</pre>

The command uninstall directive tells make to go and remove all the files and directories created with the install directive. This will (hopefully) clean up mysql from /usr/local.

The distclean directive tells make to not only delete all the compiled files but to also remove any config.cache, config.log or config.status information. Basically return the sourcetree to it's state just after untaring it.

Good, luck, have fun, and when all else fails stop by #linuxhelp on your favorite IRC network (I recommend EFnet and Undernet).

Add your own comment.