文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 2 安装 MySQL / 2.5 在 Linux 上安装 MySQL / 2.5.1 使用 MySQL Yum 存储库在 Linux 上安装 MySQL
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

2.5.1 使用 MySQL Yum 存储库在 Linux 上安装 MySQL2.5.1 Installing MySQL on Linux Using the MySQL Yum Repository

适用于 Oracle Linux、Red Hat Enterprise Linux、CentOS 和 Fedora 的 MySQL Yum 存储库提供了用于安装 MySQL 服务器、客户端、MySQL Workbench、MySQL Utilities、MySQL Router、MySQL Shell、Connector/ODBC、Connector/Python 等的 RPM 软件包(并非所有软件包都适用于所有发行版;请参阅 使用 Yum 安装其他 MySQL 产品和组件了解详细信息)。The MySQL Yum repository for Oracle Linux, Red Hat Enterprise Linux, CentOS, and Fedora provides RPM packages for installing the MySQL server, client, MySQL Workbench, MySQL Utilities, MySQL Router, MySQL Shell, Connector/ODBC, Connector/Python and so on (not all packages are available for all the distributions; see Installing Additional MySQL Products and Components with Yum for details).

开始之前Before You Start

作为一种流行的开源软件,MySQL 以其原始或重新打包的形式广泛安装在来自不同来源的许多系统上,包括不同的软件下载站点、软件存储库等。以下说明假设您的系统上尚未使用第三方分发的 RPM 软件包安装 MySQL;如果不是这种情况,请按照替换 MySQL 的本机第三方发行版中提供的说明进行操作。As a popular, open-source software, MySQL, in its original or re-packaged form, is widely installed on many systems from various sources, including different software download sites, software repositories, and so on. The following instructions assume that MySQL is not already installed on your system using a third-party-distributed RPM package; if that is not the case, follow the instructions given at Replacing a Native Third-Party Distribution of MySQL.

Note

存储库设置 RPM 文件名以 mysql84 开头,它描述了 MySQL 默认情况下启用安装的系列。在这种情况下,默认启用 MySQL 8.4 LTS 子存储库。它还包含默认禁用的其他子存储库版本,例如 MySQL 8.0 和 MySQL Innovation Series。Repository setup RPM file names begin with mysql84, which describes the MySQL series that is enabled by default for installation. In this case, the MySQL 8.4 LTS subrepository is enabled by default. It also contains other subrepository versions, such as MySQL 8.0 and the MySQL Innovation Series, which are disabled by default.

全新安装 MySQL 的步骤Steps for a Fresh Installation of MySQL

按照以下步骤选择并安装最新的 MySQL 产品:Follow these steps to choose and install the latest MySQL products:

  1. 添加 MySQL Yum 存储库Adding the MySQL Yum Repository

    将 MySQL Yum 存储库添加到系统的存储库列表中。这通常是一次性操作,通过安装 MySQL 提供的 RPM 来执行。请按照以下步骤操作:Add the MySQL Yum repository to your system's repository list. This is typically a one-time operation that is performed by installing the RPM provided by MySQL. Follow these steps:

    1. 从 MySQL 开发者专区的 MySQL Yum 存储库页面 (https://dev.mysql.com/downloads/repo/yum/) 下载它。Download it from the MySQL Yum Repository page (https://dev.mysql.com/downloads/repo/yum/) in the MySQL Developer Zone.

    2. 选择并下载适合您平台的发行包。Select and download the release package for your platform.

    3. 安装下载的发行包。包文件格式为:Install the downloaded release package. The package file format is:

      mysql84-community-release-{platform}-{version-number}.noarch.rpm
      
      • mysql84:表示默认启用的 MySQL 版本。此时默认启用 MySQL 8.4,MySQL 8.0 和 MySQL Innovation 系列均可用,但默认禁用。mysql84: Indicates the MySQL version that is enabled by default. In this case, MySQL 8.4 is enabled by default, and both MySQL 8.0 and the MySQL Innovation series are available but disabled by default.

      • {platform}:平台代码,例如 el7、el8、el9、fc41 或 fc42。 “el”代表 Enterprise Linux,“fc”代表 Fedora,以平台的基本版本号结尾。{platform}: The platform code, such as el7, el8, el9, fc41, or fc42. The 'el' represents Enterprise Linux, 'fc' for Fedora, and it ends with the platform's base version number.

      • {version-number}:MySQL 存储库配置 RPM 的版本,因为它们偶尔会收到更新。{version-number}: Version of the MySQL repository configuration RPM as they do receive occasional updates.

      安装为您的系统下载的 RPM,例如:Install the RPM you downloaded for your system, for example:

      $> sudo yum localinstall mysql84-community-release-{platform}-{version-number}.noarch.rpm
      

      安装命令将 MySQL Yum 存储库添加到系统的存储库列表中,并下载 GnuPG 密钥以检查软件包的完整性。有关 GnuPG 密钥检查的详细信息,请参阅第 2.1.4.2 节“使用 GnuPG 检查签名”。The installation command adds the MySQL Yum repository to your system's repository list and downloads the GnuPG key to check the integrity of the software packages. See Section 2.1.4.2, “Signature Checking Using GnuPG” for details on GnuPG key checking.

      您可以通过以下命令检查 MySQL Yum 仓库是否已成功添加并启用(对于 dnf 启用的系统,将命令中的yum替换为dnf):You can check that the MySQL Yum repository has been successfully added and enabled by the following command (for dnf-enabled systems, replace yum in the command with dnf):

      $> yum repolist enabled | grep mysql.*-community
      

      示例输出:Example output:

      mysql-8.4-lts-community               MySQL 8.4 LTS Community Server
      mysql-tools-8.4-lts-community            MySQL Tools 8.4 LTS Community
      

      这也表明默认情况下启用最新的 LTS MySQL 版本。选择不同版本系列的方法,例如创新轨道(今天是 9.6)或以前的系列(例如 MySQL 8.0),如下所述。This also demonstrates that the latest LTS MySQL version is enabled by default. Methods to choose a different release series, such as the innovation track (which today is 9.6) or a previous series (such as MySQL 8.0), are described below.

    Note

    在系统上启用 MySQL Yum 存储库后,通过 yum update 命令(或 dnf Upgrade 进行的任何系统范围更新支持 dnf 的系统)升级系统上的 MySQL 软件包,并替换任何本机第三方软件包(如果 Yum 在 MySQL Yum 存储库中找到它们的替代品);请参阅第 3.8 节“使用 MySQL Yum 存储库升级 MySQL”,有关其对系统可能产生的一些影响的讨论,请参阅升级共享客户端库。Once the MySQL Yum repository is enabled on your system, any system-wide update by the yum update command (or dnf upgrade for dnf-enabled systems) upgrades MySQL packages on your system and replaces any native third-party packages, if Yum finds replacements for them in the MySQL Yum repository; see Section 3.8, “Upgrading MySQL with the MySQL Yum Repository”, for a discussion on some possible effects of that on your system, see Upgrading the Shared Client Libraries.

  2. 选择版本系列Selecting a Release Series

    使用 MySQL Yum 存储库时,默认选择安装最新的 bugfix 系列(当前为 MySQL 8.4)。如果这是您想要的,您可以跳到下一步,安装 MySQL。When using the MySQL Yum repository, the latest bugfix series (currently MySQL 8.4) is selected for installation by default. If this is what you want, you can skip to the next step, Installing MySQL.

    在 MySQL Yum 存储库中,每个 MySQL 社区服务器版本系列都托管在不同的子存储库中。默认情况下启用最新 LTS 系列(当前为 MySQL 8.4)的子存储库,默认情况下禁用所有其他系列(例如 MySQL 8.0 和 MySQL Innovation 系列)的子存储库。使用此命令查看所有可用的 MySQL 相关子存储库(对于启用 dnf 的系统,请将命令中的 yum 替换为 dnf):Within the MySQL Yum repository, each MySQL Community Server release series is hosted in a different subrepository. The subrepository for the latest LTS series (currently MySQL 8.4) is enabled by default, and the subrepositories for all other series' (for example, MySQL 8.0 and the MySQL Innovation series) are disabled by default. Use this command to see all available MySQL-related subrepositories (for dnf-enabled systems, replace yum in the command with dnf):

    $> yum repolist all | grep mysql
    

    示例输出:Example output:

    mysql-connectors-community                 MySQL Connectors Community   enabled
    mysql-tools-8.4-lts-community               MySQL Tools 8.4 LTS Community        enabled
    mysql-tools-community                      MySQL Tools Community        disabled
    mysql-tools-innovation-community           MySQL Tools Innovation Commu disabled
    mysql-innovation-community                 MySQL Innovation Release Com disabled
    mysql-8.4-lts-community                          MySQL 8.4 Community LTS Server   enabled
    mysql-8.4-lts-community-debuginfo                MySQL 8.4 Community LTS Server - disabled
    mysql-8.4-lts-community-source                   MySQL 8.4 Community LTS Server - disabled
    mysql80-community                        MySQL 8.0 Community Server - disabled
    mysql80-community-debuginfo              MySQL 8.0 Community Server - disabled
    mysql80-community-source                 MySQL 8.0 Community Server - disabled
    

    要安装最新 LTS 系列以外的特定系列的最新版本,请禁用最新 LTS 系列的 bug 子存储库并启用运行安装命令之前的特定系列。如果您的平台支持 yum-config-manager 或 dnf config-manager 命令,您可以通过发出以下命令来禁用 8.4 系列的子存储库并启用 8.0 系列的子存储库:To install the latest release from a specific series other than the latest LTS series, disable the bug subrepository for the latest LTS series and enable the subrepository for the specific series before running the installation command. If your platform supports the yum-config-manager or dnf config-manager command, you can do that by issuing the following commands to disable the subrepository for the 8.4 series and enable the one for the 8.0 series:

    $> sudo yum-config-manager --disable mysql-8.4-lts-community
    $> sudo yum-config-manager --enable  mysql80-community
    

    对于支持 dnf 的平台:For dnf-enabled platforms:

    $> sudo dnf config-manager --disable mysql-8.4-lts-community
    $> sudo dnf config-manager --enable mysql80-community
    

    相反使用 config-manager 命令时,您可以通过切换 enabled 选项来手动编辑 /etc/yum.repos.d/mysql-community.repo 文件。例如,EL8 的典型默认条目:Instead of using the config-manager commands you can manually edit the /etc/yum.repos.d/mysql-community.repo file by toggling the enabled option. For example, a typical default entry for EL8:

    [mysql-8.4-lts-community]
    name=MySQL 8.4 LTS Community Server
    baseurl=http://repo.mysql.com/yum/mysql-8.4-community/el/8/$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2025
    

    找到要配置的子存储库条目并编辑 enabled 选项。指定 enabled=0 以禁用子存储库,或指定 enabled=1 以启用子存储库。例如,要从 MySQL 创新轨道进行安装,请确保您为 MySQL 8.4 子存储库条目设置了 enabled=0,并为创新条目设置了 enabled=1:Find the entry for the subrepository you want to configure and edit the enabled option. Specify enabled=0 to disable a subrepository or enabled=1 to enable a subrepository. For example, to install from the MySQL innovation track, make sure you have enabled=0 for the MySQL 8.4 subrepository entries and have enabled=1 for the innovation entries:

    [mysql80-community]
    name=MySQL 8.0 Community Server
    baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/8/$basearch
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2025
    

    您在任何时候都应该只为一个版本系列启用子存储库。You should only enable subrepository for one release series at any time.

    通过运行以下命令并检查其输出(对于启用 dnf 的情况),验证是否已启用和禁用正确的子存储库系统,请将命令中的 yum 替换为 dnf):Verify that the correct subrepositories have been enabled and disabled by running the following command and checking its output (for dnf-enabled systems, replace yum in the command with dnf):

    $> yum repolist enabled | grep mysql
    
  3. 禁用默认 MySQL 模块Disabling the Default MySQL Module

    (仅限 EL8 系统)基于 EL8 的系统(例如 RHEL8 和 Oracle Linux 8)包含一个 MySQL 模块,该模块默认启用。除非禁用此模块,否则它会屏蔽 MySQL 存储库提供的包。要禁用包含的模块并使 MySQL 存储库包可见,请使用以下命令(对于启用 dnf 的系统,请将命令中的 yum 替换为 dnf):(EL8 systems only) EL8-based systems such as RHEL8 and Oracle Linux 8 include a MySQL module that is enabled by default. Unless this module is disabled, it masks packages provided by MySQL repositories. To disable the included module and make the MySQL repository packages visible, use the following command (for dnf-enabled systems, replace yum in the command with dnf):

    $> sudo yum module disable mysql
    
  4. 安装 MySQLInstalling MySQL

    通过以下命令安装 MySQL(对于支持 dnf 的系统,将命令中的 yum 替换为 dnf):Install MySQL by the following command (for dnf-enabled systems, replace yum in the command with dnf):

    $> sudo yum install mysql-community-server
    

    这将安装 MySQL 服务器的软件包 (mysql-community-server) 以及运行服务器所需的组件的软件包,包括客户端的软件包 (mysql-community-client)、客户端和服务器的常见错误消息和字符集 (mysql-community-common) 以及共享客户端库 (mysql-community-libs)。This installs the package for MySQL server (mysql-community-server) and also packages for the components required to run the server, including packages for the client (mysql-community-client), the common error messages and character sets for client and server (mysql-community-common), and the shared client libraries (mysql-community-libs).

  5. 启动 MySQL 服务器Starting the MySQL Server

    使用以下命令启动 MySQL 服务器:Start the MySQL server with the following command:

    $> systemctl start mysqld
    

    可以使用以下命令检查 MySQL 服务器的状态:You can check the status of the MySQL server with the following command:

    $> systemctl status mysqld
    

如果操作系统启用了 systemd,则标准systemctl(或者 service,参数相反)命令,例如 stop、start、status 和restart应用于管理 MySQL 服务器服务。 mysqld 服务默认启用,并在系统重新启动时启动。有关详细信息,请参阅第 2.5.9 节“使用 systemd 管理 MySQL 服务器”。If the operating system is systemd enabled, standard systemctl (or alternatively, service with the arguments reversed) commands such as stop, start, status, and restart should be used to manage the MySQL server service. The mysqld service is enabled by default, and it starts at system reboot. See Section 2.5.9, “Managing MySQL Server with systemd” for additional information.

在服务器初始启动时,假设服务器的数据目录为空,会发生以下情况:At the initial start up of the server, the following happens, given that the data directory of the server is empty:

  • 服务器已初始化。The server is initialized.

  • 在数据中生成 SSL 证书和密钥文件目录。SSL certificate and key files are generated in the data directory.

  • validate_password 已安装并启用。validate_password is installed and enabled.

  • 超级用户帐户'root'@'localhost 已创建。设置超级用户的密码并将其存储在错误日志文件中。要显示它,请使用以下命令:A superuser account 'root'@'localhost is created. A password for the superuser is set and stored in the error log file. To reveal it, use the following command:

    $> sudo grep 'temporary password' /var/log/mysqld.log
    

    使用生成的临时密码登录并为超级用户帐户设置自定义密码,尽快更改 root 密码:Change the root password as soon as possible by logging in with the generated, temporary password and set a custom password for the superuser account:

    $> mysql -uroot -p 
    
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
    
    Note

    validate_password 默认安装。 validate_password 实施的默认密码策略要求密码至少包含 1 个大写字母、1 个小写字母、1 个数字和 1 个特殊字符,并且密码总长度至少为 8 个字符。validate_password is installed by default. The default password policy implemented by validate_password requires that passwords contain at least one uppercase letter, one lowercase letter, one digit, and one special character, and that the total password length is at least 8 characters.

有关安装后过程的详细信息,请参阅第 2.9 节“安装后设置和测试”测试”。For more information on the postinstallation procedures, see Section 2.9, “Postinstallation Setup and Testing”.

Note

基于 EL7 的平台的兼容性信息: 平台本机软件存储库中的以下 RPM 软件包与安装 MySQL 服务器的 MySQL Yum 存储库中的软件包不兼容。使用 MySQL Yum 存储库安装 MySQL 后,您将无法安装这些软件包(反之亦然)。 Compatibility Information for EL7-based platforms: The following RPM packages from the native software repositories of the platforms are incompatible with the package from the MySQL Yum repository that installs the MySQL server. Once you have installed MySQL using the MySQL Yum repository, you cannot install these packages (and vice versa).

  • akonadi-mysqlakonadi-mysql

使用 Yum 安装其他 MySQL 产品和组件Installing Additional MySQL Products and Components with Yum

您可以使用 Yum 安装和管理 MySQL 的各个组件。其中一些组件托管在 MySQL Yum 存储库的子存储库中:例如,MySQL 连接器可在 MySQL Connectors Community 子存储库中找到,MySQL Workbench 可在 MySQL Tools Community 中找到。您可以使用以下命令从 MySQL Yum 存储库列出适用于您的平台的所有 MySQL 组件的软件包(对于启用 dnf 的系统,请将命令中的 yum 替换为 dnf):You can use Yum to install and manage individual components of MySQL. Some of these components are hosted in sub-repositories of the MySQL Yum repository: for example, the MySQL Connectors are to be found in the MySQL Connectors Community sub-repository, and the MySQL Workbench in MySQL Tools Community. You can use the following command to list the packages for all the MySQL components available for your platform from the MySQL Yum repository (for dnf-enabled systems, replace yum in the command with dnf):

$> sudo yum --disablerepo=\* --enablerepo='mysql*-community*' list available

使用以下命令安装您选择的任何软件包,替换 package-name 为软件包名称(对于启用 dnf 的系统,请将命令中的 yum 替换为 dnf):Install any packages of your choice with the following command, replacing package-name with name of the package (for dnf-enabled systems, replace yum in the command with dnf):

$> sudo yum install package-name

例如,要在 Fedora 上安装 MySQL Workbench:For example, to install MySQL Workbench on Fedora:

$> sudo dnf install mysql-workbench-community

要安装共享客户端库(对于启用 dnf 的系统)系统,请将命令中的 yum 替换为 dnf):To install the shared client libraries (for dnf-enabled systems, replace yum in the command with dnf):

$> sudo yum install mysql-community-libs

平台特定说明Platform Specific Notes

ARM 支持ARM Support

Oracle Linux 7 支持 ARM 64 位 (aarch64),并且需要 Oracle Linux 7 软件集合存储库 (ol7_software_collections)。例如,要安装服务器:ARM 64-bit (aarch64) is supported on Oracle Linux 7 and requires the Oracle Linux 7 Software Collections Repository (ol7_software_collections). For example, to install the server:

$> yum-config-manager --enable ol7_software_collections
$> yum install mysql-community-server

使用 Yum 更新 MySQLUpdating MySQL with Yum

除了安装之外,您还可以使用 MySQL Yum 存储库对 MySQL 产品和组件执行更新。有关详细信息,请参阅第 3.8 节“使用 MySQL Yum 存储库升级 MySQL”。Besides installation, you can also perform updates for MySQL products and components using the MySQL Yum repository. See Section 3.8, “Upgrading MySQL with the MySQL Yum Repository” for details.

替换本机第三方发行版 MySQLReplacing a Native Third-Party Distribution of MySQL

如果您从本机软件存储库(即您自己的 Linux 发行版提供的软件存储库)安装了 MySQL 的第三方发行版,请按照以下步骤操作:If you have installed a third-party distribution of MySQL from a native software repository (that is, a software repository provided by your own Linux distribution), follow these steps:

  1. 备份数据库Backing Up Your Database

    为避免数据丢失,请在尝试使用 MySQL Yum 存储库替换 MySQL 安装之前,务必备份数据库。有关如何备份数据库的信息,请参阅第 9 章备份与恢复。To avoid loss of data, always back up your database before trying to replace your MySQL installation using the MySQL Yum repository. See Chapter 9, Backup and Recovery, on how to back up your database.

  2. 添加 MySQL Yum 存储库Adding the MySQL Yum Repository

    按照 添加 MySQL Yum 存储库。Add the MySQL Yum repository to your system's repository list by following the instructions given in Adding the MySQL Yum Repository.

  3. 通过 Yum 更新或 DNF 升级替换本机第三方发行版Replacing the Native Third-Party Distribution by a Yum Update or a DNF Upgrade

    按照设计,当您在系统上执行 yum update 命令(或 dnf 升级,对于支持 dnf 的系统)或 yum update 时,MySQL Yum 存储库会使用 MySQL Yum 存储库中最新的错误修复版本替换您的本机第三方 MySQL mysql-server(或 dnf 升级 mysql-server 对于支持 dnf 的系统)。By design, the MySQL Yum repository replaces your native, third-party MySQL with the latest bugfix release from the MySQL Yum repository when you perform a yum update command (or dnf upgrade for dnf-enabled systems) on the system, or a yum update mysql-server (or dnf upgrade mysql-server for dnf-enabled systems).

使用 Yum 存储库更新 MySQL 后,使用旧版本共享客户端库编译的应用程序应该可以继续工作。但是,如果您想要重新编译应用程序并将其与更新的库动态链接,请参阅升级共享客户端库,了解一些特殊注意事项。After updating MySQL using the Yum repository, applications compiled with older versions of the shared client libraries should continue to work. However, if you want to recompile applications and dynamically link them with the updated libraries, see Upgrading the Shared Client Libraries, for some special considerations.

Note

对于基于 EL7 的平台:请参阅基于 EL7 的平台的兼容性信息。For EL7-based platforms: See Compatibility Information for EL7-based platforms.