
2.2. Installing MySQL from Generic Binaries on Unix/Linux

   Oracle provides a set of binary distributions of MySQL. We offer
   binary distributions for a number of platforms in the form of
   compressed tar files (files with a .tar.gz extension), as well as
   binaries in platform-specific package formats for selected
   platforms.

   This section covers the installation of MySQL binary distributions
   from a compressed tar file. For other platform-specific package
   formats, see the other platform-specific sections. For example,
   for Windows distributions, see Section 2.3, "Installing MySQL on
   Microsoft Windows."

   To obtain MySQL, see Section 2.1.3, "How to Get MySQL."

   On Unix, to install a compressed tar file binary distribution,
   unpack it at the installation location you choose (typically
   /usr/local/mysql). This creates the directories shown in the
   following table.

   Table 2.2. MySQL Installation Layout for Generic Unix/Linux Binary
   Package
   Directory Contents of Directory
   bin Client programs and the mysqld server
   data Log files, databases
   docs Manual in Info format
   man Unix manual pages
   include Include (header) files
   lib Libraries
   scripts mysql_install_db
   share Miscellaneous support files, including error messages,
   sample configuration files, SQL for database installation
   sql-bench Benchmarks

   Debug versions of the mysqld binary are available as mysqld-debug.
   To compile a debug version of MySQL from a source distribution,
   you should add -DWITH_DEBUG=1 to the CMake command used to
   configure the distribution. For more information on compiling from
   source, see Section 2.11, "Installing MySQL from Source."

   MySQL compressed tar file binary distributions have names of the
   form mysql-VERSION-OS.tar.gz, where VERSION is a number (for
   example, 5.5.9), and OS indicates the type of operating system for
   which the distribution is intended (for example, pc-linux-i686 or
   winx64).

   To install MySQL from a compressed tar file binary distribution,
   your system must have the following tools:

     * GNU gunzip to uncompress the distribution.

     * A reasonable tar to unpack the distribution. If your tar
       program supports the z option, it can both uncompress and
       unpack the file. GNU tar is known to work. The standard tar
       provided with some operating systems is not able to unpack the
       long file names in the MySQL distribution. You should download
       and install GNU tar, or if available, use a preinstalled
       version of GNU tar. Usually this is available as gnutar, gtar,
       or as tar within a GNU or Free Software directory, such as
       /usr/sfw/bin or /usr/local/bin. GNU tar is available from
       http://www.gnu.org/software/tar/.

   Warning

   If you have previously installed a MySQL installation using your
   operating system native package management system, such as yum or
   apt-get, you may experience problems installing using a native
   binary. Make sure your previous MySQL previous installation has
   been removed entirely (using your package management system), and
   that any additional files, such as old versions of your data
   files, have also been removed. You should also check the existence
   of configuration files such as /etc/my.cnf or the /etc/mysql
   directory have been deleted.

   If you run into problems and need to file a bug report, please use
   the instructions in Section 1.7, "How to Report Bugs or Problems."

   The basic commands that you must execute to install and use a
   MySQL binary distribution are shown following.
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> cp /usr/local/mysql/support-files/my-small/etc/my.cnf # Option
al
shell> bin/mysqld_safe --user=mysql &
shell> cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mys
ql.server # Optional

   A more detailed version of the preceding description for
   installing a binary distribution follows.
   Note

   This procedure assumes that you have root (administrator) access
   to your system. Alternatively you can prefix each command using
   the sudo (Linux) or pfexec (OpenSolaris) command.

   This procedure does not set up any passwords for MySQL accounts.
   After following the procedure, proceed to Section 2.12,
   "Postinstallation Setup and Testing."

Create a mysql User and Group

   If your system does not already have a user and group for mysqld
   to run as, you may need to create one.
shell> groupadd mysql
shell> useradd -r -g mysql mysql

   Note

   The above will create a user that has login permissions to your
   server. You may wish to disable the account, as the user is only
   required for ownership purposes, not login purposes. You can do
   this on Linux by using the -r command-line option.

   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.

Obtain and Unpack the Distribution

   Pick the directory under which you want to unpack the distribution
   and change location into it. The example here unpacks the
   distribution under /usr/local. (The instructions, therefore,
   assume that you have permission to create files and directories in
   /usr/local. If that directory is protected, you must perform the
   installation as root.)
shell> cd /usr/local

   Obtain a distribution file using the instructions in Section
   2.1.3, "How to Get MySQL." For a given release, binary
   distributions for all platforms are built from the same MySQL
   source distribution.

   Unpack the distribution, which creates the installation directory.
   Then create a symbolic link to that directory. tar can uncompress
   and unpack the distribution if it has z option support:
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql

   The tar command creates a directory named mysql-VERSION-OS. The ln
   command makes a symbolic link to that directory. This enables you
   to refer more easily to the installation directory as
   /usr/local/mysql.

   If your tar does not have z option support, use gunzip to unpack
   the distribution and tar to unpack it. Replace the preceding tar
   command with the following alternative command to uncompress and
   extract the distribution:
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -

Perform Postinstallation Setup


    1. Change location into the installation directory:
shell> cd mysql
       You will find several files and subdirectories in the mysql
       directory. The most important for installation purposes are
       the bin and scripts subdirectories:

          + The bin directory contains client programs and the
            server. You should add the full path name of this
            directory to your PATH environment variable so that your
            shell finds the MySQL programs properly. See Section
            2.14, "Environment Variables."

          + The scripts directory contains the mysql_install_db
            script used to initialize the mysql database containing
            the grant tables that store the server access
            permissions.

    2. Ensure that the distribution contents are accessible to mysql.
       If you unpacked the distribution as mysql, no further action
       is required. If you unpacked the distribution as root, its
       contents will be owned by root. Change its ownership 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.

    3. If you have not installed MySQL before, you must create the
       MySQL data directory and initialize the grant tables:
shell> scripts/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 that user,
       you can omit the --user option.
       The command should create the data directory and its contents
       with mysql as the owner.
       After creating or updating the grant tables, you need to
       restart the server manually.

    4. 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 data

    5. You may want to optionally copy one of the provided
       configuration files from the support-files directory into your
       /etc directory. There are different sample configuration files
       for different use cases, server types, and CPU and RAM
       configurations. If you want to use one of these standard
       files, you should copy it to /etc/my.cnf, or /etc/mysql/my.cnf
       and edit and check the configuration before starting your
       MySQL server for the first time.
       If you do not copy one of the standard configuration files,
       the MySQL server will be started with the default settings.

    6. 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 or by
       setting --secure-file-priv to a directory where SELECT writes
       can be made safely.

    7. 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 support-files/mysql.server
       script itself and in Section 2.12.1.2, "Starting and Stopping
       MySQL Automatically."

    8. 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.13, "mysql_setpermission --- Interactively Set
       Permissions in Grant Tables." For Perl module installation
       instructions, see Section 2.15, "Perl Installation Notes."

    9. If you would like to use mysqlaccess and have the MySQL
       distribution in some nonstandard location, you must change the
       location where mysqlaccess expects to find the mysql client.
       Edit the bin/mysqlaccess script at approximately line 18.
       Search for a line that looks like this:
$MYSQL     = '/usr/local/bin/mysql';    # path to mysql executable
       Change the path to reflect the location where mysql actually
       is stored on your system. If you do not do this, a Broken pipe
       error will occur when you run mysqlaccess.

   After everything has been unpacked and installed, you should test
   your distribution. To start the MySQL server, use the following
   command:
shell> bin/mysqld_safe --user=mysql &

   If you run the command as root, you must use the --user option as
   shown. The value of the option is the name of the login account
   that you created in the first step to use for running the server.
   If you run the command while logged in as mysql, you can omit the
   --user option.

   If the command fails immediately and prints mysqld ended, you can
   find some information in the host_name.err file in the data
   directory.

   More information about mysqld_safe is given in Section 4.3.2,
   "mysqld_safe --- MySQL Server Startup Script."
   Note

   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."
