MySQL Secure Deployment Guide  /  Installing the MySQL Binary Package

Chapter 4 Installing the MySQL Binary Package

This section covers installation prerequisites, creating the mysql user and group, and unpacking the distribution.

Installation Prerequisites

  • The installation must be performed as an operating system root user, as the installation process involves creating a user, a group, directories, and assigning ownership and permissions. Installed MySQL binaries are owned by the operating system root user.

    Note

    Unless otherwise indicated, procedures in this guide are performed as the operating system root user.

  • MySQL has a dependency on the libaio library. Data directory initialization and subsequent server startup steps fail if this library is not installed locally. If necessary, install it using the appropriate package manager. For example, on Yum-based systems:

    $> yum search libaio  # search for info
    $> yum install libaio # install library
  • Oracle Linux 8 does not install the file /lib64/libtinfo.so.5 by default, which is required by the MySQL client bin/mysql for mysql-VERSION-linux-glibc2.12-x86_64.tar.xz packages. To work around this issue, install the ncurses-compat-libs package:

    $> yum install ncurses-compat-libs

Creating the mysql User and Group

The mysql user owns the MySQL data directory. It is also used to run the mysqld server process, as defined in the systemd mysqld.service file (see Starting the Server using systemd). The mysql user has read and write access to anything in the MySQL data directory. It does not have the ability to log into MySQL. It only exists for ownership purposes.

The mysql group is the database administrator group. Users in this group have read and write access to anything in the MySQL data directory, and execute access on any packaged MySQL binary.

This command adds the mysql group.

$> groupadd -g 27 -o -r mysql

The groupadd -g 27 and -o options assign a non-unique group ID (GID). The -r option makes the group a system group.

This command adds the mysql user:

$> useradd -M -N -g mysql -o -r -d datadir -s /bin/false -c "MySQL Server" -u 27 mysql
  • The -M option prevents the creation of a user home directory.

  • The -N option indicates that the user should be added to the group specified by the -g option.

  • The -o and -u 27 options assign a non-unique user ID (UID).

  • The -r and -s /bin/false options create a user without login permissions to the server host. The mysql user is required only for ownership purposes, not login purposes.

  • The -d option specifies the user login directory, which is set to the expected MySQL data directory path. The expected data directory path in this deployment is /usr/local/mysql/data.

  • The -c option specifies a comment describing the account.

Unpacking the Distribution

To extract the binary files from the verified MySQL Linux Generic Binary download package:

  1. Change location to the directory under which you want to unpack the MySQL distribution. In this deployment, the distribution is unpackaged by root under /usr/local.

    $> cd /usr/local
  2. Unpack the MySQL distribution, which creates the installation directory. Any modern tar program can uncompress and unpack the distribution with this command:

    $> tar xvf /path/to/mysql-commercial-8.0.xx-linux-glibc2.12-x86_64.tar.xz

    The tar command creates a directory named mysql-VERSION-OS. In this case, the directory is named mysql-commercial-8.0.xx-linux-glibc2.12-x86_64, where xx is the latest release.

  3. Create a relative symbolic link to the installation directory created by tar:

    $> cd /usr/local
    $> ln -s mysql-commercial-8.0.xx-linux-glibc2.12-x86_64 mysql

    The ln command makes a symbolic link to the installation directory. This enables you to refer more easily to it as /usr/local/mysql.

Note

To avoid typing the path name of client programs when working with MySQL, add the /usr/local/mysql/bin directory to your PATH variable:

$> export PATH=/usr/local/mysql/bin:$PATH

Unpacking the distribution creates the directories shown in the following table. The directories are located in the MySQL installation directory, which is /usr/local/mysql:

Table 4.1 MySQL Linux Generic Binary Distribution Directories

Directory Contents of Directory
bin mysqld server; client and utility programs
docs MySQL manual in Info format
man Unix manual pages
include Include (header) files
lib Libraries
share Miscellaneous files, including error messages, sample configuration files, SQL for database installation
support-files Miscellaneous support files related to managing multiple server processes, automatic startup configuration, and log rotation.

Also included in the MySQL installation directory are the README and LICENSE files. There is no data directory. It is created later when the data directory is initialized.