8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 2 安装 MySQL / 2.2 使用通用二进制文件在 Unix/Linux 上安装 MySQL
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

2.2 使用通用二进制文件在 Unix/Linux 上安装 MySQL2.2 Installing MySQL on Unix/Linux Using Generic Binaries

Oracle 提供了一组 MySQL 的二进制发行版。其中包括适用于多种平台的压缩 tar 文件(带有 .tar.xz 扩展名的文件)形式的通用二进制发行版,以及适用于选定平台的平台特定软件包格式的二进制文件。Oracle provides a set of binary distributions of MySQL. These include generic binary distributions in the form of compressed tar files (files with a .tar.xz extension) for a number of platforms, and binaries in platform-specific package formats for selected platforms.

本节介绍如何在 Unix/Linux 上通过压缩 tar 文件二进制发行版安装 MySQL 平台。有关重点关注 MySQL 安全功能的 Linux 通用二进制发行版安装说明,请参阅安全部署指南。对于其他特定于平台的二进制包格式,请参阅本手册中其他特定于平台的部分。例如,对于 Windows 发行版,请参阅第 2.3 节“在 Microsoft Windows 上安装 MySQL”。请参阅第 2.1.3 节“如何获取 MySQL”,了解如何以不同的发行版格式获取 MySQL。This section covers the installation of MySQL from a compressed tar file binary distribution on Unix/Linux platforms. For Linux-generic binary distribution installation instructions with a focus on MySQL security features, refer to the Secure Deployment Guide. For other platform-specific binary package formats, see the other platform-specific sections in this manual. For example, for Windows distributions, see Section 2.3, “Installing MySQL on Microsoft Windows”. See Section 2.1.3, “How to Get MySQL” on how to obtain MySQL in different distribution formats.

MySQL 压缩 tar 文件二进制发行版的名称格式为 mysql-VERSION-OS.tar.xz,其中 VERSION 是一个数字(例如,8.4.9),OS 表示要分发的操作系统类型(例如,pc-linux-i686 或 winx64)。MySQL compressed tar file binary distributions have names of the form mysql-VERSION-OS.tar.xz, where VERSION is a number (for example, 8.4.9), and OS indicates the type of operating system for which the distribution is intended (for example, pc-linux-i686 or winx64).

还有 MySQL 压缩的“最小安装”版本 Linux 通用二进制发行版的 class="command">tar 文件,其名称格式为 mysql-VERSION-OS-GLIBCVER-ARCH-minimal.tar.xz。最小安装发行版不包括调试二进制文件,并删除了调试符号,使其比常规二进制发行版小得多。如果您选择安装最小安装发行版,请记住根据后面的说明调整文件名格式的差异。There is also a “minimal install” version of the MySQL compressed tar file for the Linux generic binary distribution, which has a name of the form mysql-VERSION-OS-GLIBCVER-ARCH-minimal.tar.xz. The minimal install distribution excludes debug binaries and is stripped of debug symbols, making it significantly smaller than the regular binary distribution. If you choose to install the minimal install distribution, remember to adjust for the difference in file name format in the instructions that follow.

Warnings
  • 如果您之前使用操作系统本机包管理系统(例如 Yum 或 APT)安装了 MySQL,则使用本机二进制文件安装时可能会遇到问题。确保您以前安装的 MySQL 已被完全删除(使用您的包管理系统),并且所有其他文件(例如旧版本的数据文件)也已被删除。您还应该检查配置文件,例如 /etc/my.cnf 或 /etc/mysql 目录,并将其删除。If you have previously installed MySQL using your operating system native package management system, such as Yum or APT, you may experience problems installing using a native binary. Make sure your previous MySQL 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 for configuration files such as /etc/my.cnf or the /etc/mysql directory and delete them.

    有关使用官方 MySQL 软件包替换第三方软件包的信息,请参阅 替换 MySQL 的本机第三方发行版 或 使用 MySQL APT 存储库替换 MySQL 的本机发行版。For information about replacing third-party packages with official MySQL packages, see Replacing a Native Third-Party Distribution of MySQL or Replacing a Native Distribution of MySQL Using the MySQL APT Repository.

  • MySQL 依赖于 libaio 库。如果本地未安装此库,数据目录初始化和后续服务器启动步骤将失败。如有必要,请使用适当的包管理器安装它。例如,在基于 Yum 的系统上: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
    

    或者,在基于 APT 的系统上:Or, on APT-based systems:

    $> apt-cache search libaio # search for info
    $> apt-get install libaio1 # install library
    
  • Oracle Linux 8 和 9 / Red Hat 8 和 9(EL8 和 EL9):默认情况下,这些平台不会安装 MySQL 客户端所需的文件 /lib64/libtinfo.so.5 bin/mysql 用于软件包 mysql-VERSION-el7-x86_64.tar.gz 和 mysql-VERSION-linux-glibc2.12-x86_64.tar.xz。要解决此问题,请安装 ncurses-compat-libs 软件包:Oracle Linux 8 and 9 / Red Hat 8 and 9 (EL8 and EL9): These platforms by default do not install the file /lib64/libtinfo.so.5, which is required by the MySQL client bin/mysql for packages mysql-VERSION-el7-x86_64.tar.gz and mysql-VERSION-linux-glibc2.12-x86_64.tar.xz. To work around this issue, install the ncurses-compat-libs package:

    $> yum install ncurses-compat-libs
    
  • 如果 Oracle(或您的 Linux 供应商)未提供特定于您的发行版的 RPM 或 .deb 文件,您可以尝试通用二进制文件。在某些情况下,由于库不兼容或其他问题,这些可能不适用于您的 Linux 安装。在这种情况下,您可以尝试从源代码编译并安装 MySQL。有关详细信息和说明,请参阅第 2.8 节“从源代码安装 MySQL”。If no RPM or .deb file specific to your distribution is provided by Oracle (or by your Linux vendor), you can try the generic binaries. In some cases, due to library incompatibilities or other issues, these may not work with your Linux installation. In such cases, you can try to compile and install MySQL from source. See Section 2.8, “Installing MySQL from Source”, for more information and instructions.

要安装压缩的 tar 文件二进制分发版,请将其解压到您选择的安装位置(通常为 /usr/local/mysql)。这将创建下表所示的目录。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.

表 2.3 通用 Unix/Linux 二进制包的 MySQL 安装布局Table 2.3 MySQL Installation Layout for Generic Unix/Linux Binary Package

目录Directory 目录内容Contents of Directory
binbin mysqld 服务器、客户端和实用程序mysqld server, client and utility programs
docsdocs Info 格式的 MySQL 手册MySQL manual in Info format
manman Unix 手册页Unix manual pages
includeinclude 包含(标题)文件Include (header) files
liblib 库Libraries
shareshare 数据库安装的错误消息、字典和 SQLError messages, dictionary, and SQL for database installation
support-filessupport-files 其他支持文件Miscellaneous support files

mysqld 二进制文件可作为mysqld-debug 获得。要从源代码发行版编译您自己的 MySQL 调试版本,请使用适当的配置选项来启用调试支持。请参阅第 2.8 节“从源代码安装 MySQL”。Debug versions of the mysqld binary are available as mysqld-debug. To compile your own debug version of MySQL from a source distribution, use the appropriate configuration options to enable debugging support. See Section 2.8, “Installing MySQL from Source”.

要安装和使用 MySQL 二进制发行版,命令序列如下所示:To install and use a MySQL binary distribution, the command sequence looks like this:

$> groupadd mysql
$> useradd -r -g mysql -s /bin/false mysql
$> cd /usr/local
$> tar xvf /path/to/mysql-VERSION-OS.tar.xz
$> ln -s full-path-to-mysql-VERSION-OS mysql
$> cd mysql
$> mkdir mysql-files
$> chown mysql:mysql mysql-files
$> chmod 750 mysql-files
$> bin/mysqld --initialize --user=mysql
$> bin/mysqld_safe --user=mysql &
# Next command is optional
$> cp support-files/mysql.server /etc/init.d/mysql.server
Note

此过程假定您拥有系统的root(管理员)访问权限。或者,您可以使用 sudo (Linux) 或 pfexec (Solaris) 命令为每个命令添加前缀。This procedure assumes that you have root (administrator) access to your system. Alternatively, you can prefix each command using the sudo (Linux) or pfexec (Solaris) command.

mysql-files 目录提供了一个方便的位置,可用作 secure_file_priv 系统变量的值,该变量限制导入和导出对特定目录的操作。请参阅第 7.1.8 节“服务器系统变量”。The mysql-files directory provides a convenient location to use as the value for the secure_file_priv system variable, which limits import and export operations to a specific directory. See Section 7.1.8, “Server System Variables”.

下面是上述安装二进制发行版说明的更详细版本。A more detailed version of the preceding description for installing a binary distribution follows.

创建 mysql 用户和组Create a mysql User and Group

如果您的系统还没有用于运行 mysqld 的用户和组,您可能需要创建它们。以下命令添加 mysql 组和 mysql 用户。您可能想将用户和组称为其他名称,而不是 mysql。如果是这样,请在以下说明中替换为适当的名称。 useradd 和 groupadd 的语法在不同版本的 Unix/Linux 上可能略有不同,或者它们可能具有不同的名称,例如 adduser 和 addgroup。If your system does not already have a user and group to use for running mysqld, you may need to create them. The following commands add the mysql group and the mysql user. You might want to call the user and group something else instead of mysql. If so, substitute the appropriate name in the following instructions. The syntax for useradd and groupadd may differ slightly on different versions of Unix/Linux, or they may have different names such as adduser and addgroup.

$> groupadd mysql
$> useradd -r -g mysql -s /bin/false mysql
Note

由于仅出于所有权目的而不是登录目的需要用户,因此 useradd 命令使用 -r 和 -s /bin/false 选项来创建没有服务器主机登录权限的用户。如果您的 useradd 不支持这些选项,请忽略这些选项。Because the user is required only for ownership purposes, not login purposes, the useradd command uses the -r and -s /bin/false options to create a user that does not have login permissions to your server host. Omit these options if your useradd does not support them.

获取并解压发行版Obtain and Unpack the Distribution

选择要解压发行版的目录并将位置更改到其中。此处的示例将发行版解压到 /usr/local 下。因此,这些说明假定您有权在 /usr/local 中创建文件和目录。如果该目录受保护,则必须以 root 身份执行安装。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.

$> cd /usr/local

按照第 2.1.3 节“如何获取 MySQL” 中的说明获取分发文件。对于给定版本,所有平台的二进制发行版都是从相同的 MySQL 源发行版构建的。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.

解压发行版,这会创建安装目录。 tar 如果支持 z 选项,则可以解压缩发行版:Unpack the distribution, which creates the installation directory. tar can uncompress and unpack the distribution if it has z option support:

$> tar xvf /path/to/mysql-VERSION-OS.tar.xz

tar 命令创建一个名为 mysql-VERSION-OS。The tar command creates a directory named mysql-VERSION-OS.

要从压缩的 tar 文件二进制分发版安装 MySQL,您的系统必须有 GNU XZ Utils 来解压缩该分发版,并具有合理的 tar 来解压它。To install MySQL from a compressed tar file binary distribution, your system must have GNU XZ Utils to uncompress the distribution and a reasonable tar to unpack it.

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或者/usr/local/bin. GNU tar is available from http://www.gnu.org/software/tar/.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/.

如果您的 tar 不支持 xz 格式然后使用 xz 命令解压发行版并使用 tar 解压它。将前面的 tar 命令替换为以下替代命令,以解压缩并提取分发版:If your tar does not support the xz format then use the xz command 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:

$> xz -dc /path/to/mysql-VERSION-OS.tar.xz | tar x

接下来,创建一个指向由 tar 创建的安装目录的符号链接:Next, create a symbolic link to the installation directory created by tar:

$> ln -s full-path-to-mysql-VERSION-OS mysql

ln 命令创建指向安装目录的符号链接。这使您可以更轻松地将其引用为 /usr/local/mysql。为了避免在使用 MySQL 时必须始终键入客户端程序的路径名,您可以将 /usr/local/mysql/bin 目录添加到 PATH 变量中:The ln command makes a symbolic link to the installation directory. This enables you to refer more easily to it as /usr/local/mysql. To avoid having to type the path name of client programs always when you are working with MySQL, you can add the /usr/local/mysql/bin directory to your PATH variable:

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

执行安装后设置Perform Postinstallation Setup

安装过程的其余部分包括设置分发所有权和访问权限、初始化数据目录、启动 MySQL 服务器以及设置配置文件。有关说明,请参阅第 2.9 节“安装后设置和测试”。The remainder of the installation process involves setting distribution ownership and access permissions, initializing the data directory, starting the MySQL server, and setting up the configuration file. For instructions, see Section 2.9, “Postinstallation Setup and Testing”.