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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 2 安装 MySQL / 2.5 在 Linux 上安装 MySQL / 2.5.4 使用 Oracle 的 RPM 软件包在 Linux 上安装 MySQL
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

2.5.4 使用 Oracle 的 RPM 软件包在 Linux 上安装 MySQL2.5.4 Installing MySQL on Linux Using RPM Packages from Oracle

在 Linux 上安装 MySQL 的推荐方法基于 RPM 的 Linux 发行版是使用 Oracle 提供的 RPM 包。对于 MySQL 社区版,有两个来源可以获取它们:The recommended way to install MySQL on RPM-based Linux distributions is by using the RPM packages provided by Oracle. There are two sources for obtaining them, for the Community Edition of MySQL:

Note

其他供应商也提供 MySQL 的 RPM 发行版。请注意,它们在特性、功能和约定(包括通信设置)方面可能与 Oracle 构建的产品不同,并且本手册中的安装说明不一定适用于它们。应参阅供应商的说明。RPM distributions of MySQL are also provided by other vendors. Be aware that they may differ from those built by Oracle in features, capabilities, and conventions (including communication setup), and that the installation instructions in this manual do not necessarily apply to them. The vendor's instructions should be consulted instead.

MySQL RPM 软件包MySQL RPM Packages

表 2.10 MySQL 社区版 RPM 软件包Table 2.10 RPM Packages for MySQL Community Edition

软件包名称Package Name 摘要Summary
mysql-community-clientmysql-community-client MySQL 客户端应用程序和 toolsMySQL client applications and tools
mysql-community-client-pluginsmysql-community-client-plugins MySQL 客户端应用程序的共享插件Shared plugins for MySQL client applications
mysql-community-commonmysql-community-common 服务器和客户端库的通用文件Common files for server and client libraries
mysql-community-develmysql-community-devel MySQL 数据库的开发头文件和库客户端应用程序Development header files and libraries for MySQL database client applications
mysql-community-embedded-compatmysql-community-embedded-compat MySQL 服务器作为嵌入式库,兼容使用该库版本 18 的应用程序MySQL server as an embedded library with compatibility for applications using version 18 of the library
mysql-community-icu-data-filesmysql-community-icu-data-files MySQL 正则表达式所需的 ICU 数据文件的 MySQL 打包MySQL packaging of ICU data files needed by MySQL regular expressions
mysql-community-libsmysql-community-libs MySQL 数据库客户端应用程序的共享库Shared libraries for MySQL database client applications
mysql-community-libs-compatmysql-community-libs-compat 以前 MySQL 安装的共享兼容性库;仅当平台支持以前的 MySQL 版本时才出现Shared compatibility libraries for previous MySQL installations; only present if previous MySQL versions are supported by the platform
mysql-community-servermysql-community-server 数据库服务器和相关工具Database server and related tools
mysql-community-server-debugmysql-community-server-debug 调试服务器和插件二进制文件Debug server and plugin binaries
mysql-community-testmysql-community-test 测试套件 MySQL 服务器Test suite for the MySQL server
mysql-communitymysql-community 源代码 RPM 类似于 mysql-community-8.4.9-1.el7.src.rpm,具体取决于所选操作系统The source code RPM looks similar to mysql-community-8.4.9-1.el7.src.rpm, depending on selected OS
其他 *debuginfo* RPMAdditional *debuginfo* RPMs 有几个 debuginfo 软件包:mysql-community-client-debuginfo、 mysql-community-libs-debuginfo mysql-community-server-debug-debuginfo mysql-community-server-debuginfo 和 mysql-community-test-debuginfo。There are several debuginfo packages: mysql-community-client-debuginfo, mysql-community-libs-debuginfo mysql-community-server-debug-debuginfo mysql-community-server-debuginfo, and mysql-community-test-debuginfo.

表 2.11 MySQL 企业版 RPM 软件包Table 2.11 RPM Packages for the MySQL Enterprise Edition

软件包名称Package Name 摘要Summary
mysql-commercial-backupmysql-commercial-backup MySQL Enterprise 备份MySQL Enterprise Backup
mysql-commercial-clientmysql-commercial-client MySQL 客户端应用程序和 toolsMySQL client applications and tools
mysql-commercial-client-pluginsmysql-commercial-client-plugins MySQL 客户端应用程序的共享插件Shared plugins for MySQL client applications
mysql-commercial-commonmysql-commercial-common 服务器和客户端库的通用文件Common files for server and client libraries
mysql-commercial-develmysql-commercial-devel MySQL 数据库的开发头文件和库客户端应用程序Development header files and libraries for MySQL database client applications
mysql-commercial-embedded-compatmysql-commercial-embedded-compat MySQL 服务器作为嵌入式库,兼容使用该库版本 18 的应用程序MySQL server as an embedded library with compatibility for applications using version 18 of the library
mysql-commercial-icu-data-filesmysql-commercial-icu-data-files MySQL 正则表达式所需的 ICU 数据文件的 MySQL 打包MySQL packaging of ICU data files needed by MySQL regular expressions
mysql-commercial-libsmysql-commercial-libs MySQL 数据库客户端应用程序的共享库Shared libraries for MySQL database client applications
mysql-commercial-libs-compatmysql-commercial-libs-compat 以前 MySQL 安装的共享兼容性库;仅当平台支持以前的 MySQL 版本时才存在。库的版本与您使用的发行版默认安装的库的版本相匹配。Shared compatibility libraries for previous MySQL installations; only present if previous MySQL versions are supported by the platform. The version of the libraries matches the version of the libraries installed by default by the distribution you are using.
mysql-commercial-servermysql-commercial-server 数据库服务器和相关工具Database server and related tools
mysql-commercial-testmysql-commercial-test 测试套件 MySQL 服务器Test suite for the MySQL server
其他 *debuginfo* RPMAdditional *debuginfo* RPMs 有几个 debuginfo 包:mysql-commercial-client-debuginfo、mysql-commercial-libs-debuginfo mysql-commercial-server-debug-debuginfo mysql-commercial-server-debuginfo 和 mysql-commercial-test-debuginfo。There are several debuginfo packages: mysql-commercial-client-debuginfo, mysql-commercial-libs-debuginfo mysql-commercial-server-debug-debuginfo mysql-commercial-server-debuginfo, and mysql-commercial-test-debuginfo.

RPM 的全名具有以下语法:The full names for the RPMs have the following syntax:

packagename-version-distribution-arch.rpm

distribution 和 arch 值指示 Linux 发行版及其处理器类型包已构建。请参阅下表,了解分发标识符列表:The distribution and arch values indicate the Linux distribution and the processor type for which the package was built. See the table below for lists of the distribution identifiers:

表 2.12 MySQL Linux RPM 软件包分发标识符Table 2.12 MySQL Linux RPM Package Distribution Identifiers

分发值Distribution Value 预期用途Intended Use
el{version} 其中 {version} 是主要的 Enterprise Linux 版本,例如el8el{version} where {version} is the major Enterprise Linux version, such as el8 基于 EL6 (8.0)、EL7、EL8、EL9 和 EL10 的平台(例如 Oracle Linux、Red Hat Enterprise Linux 和 CentOS 的相应版本)EL6 (8.0), EL7, EL8, EL9, and EL10-based platforms (for example, the corresponding versions of Oracle Linux, Red Hat Enterprise Linux, and CentOS)
fc{version},其中 {version} 是主要版本 Fedora 版本,例如 fc37fc{version} where {version} is the major Fedora version, such as fc37 Fedora 41 和 42Fedora 41 and 42
sl5sl5 SUSE Linux Enterprise Server 15SUSE Linux Enterprise Server 15

要查看 RPM 包中的所有文件(例如 mysql-community-server),请使用以下命令命令:To see all files in an RPM package (for example, mysql-community-server), use the following command:

$> rpm -qpl mysql-community-server-version-distribution-arch.rpm

本节其余部分的讨论仅适用于使用直接从 Oracle 下载的 RPM 包的安装过程,而不是通过 MySQL 存储库。The discussion in the rest of this section applies only to an installation process using the RPM packages directly downloaded from Oracle, instead of through a MySQL repository.

某些包之间存在依赖关系。如果您计划安装许多软件包,您可能希望下载 RPM 捆绑包 tar 文件,其中包含上面列出的所有 RPM 软件包,这样您就无需单独下载它们。Dependency relationships exist among some of the packages. If you plan to install many of the packages, you may wish to download the RPM bundle tar file instead, which contains all the RPM packages listed above, so that you need not download them separately.

在大多数情况下,您需要安装 mysql-community-server、mysql-community-client、mysql-community-client-plugins、mysql-community-libs、mysql-community-icu-data-files、mysql-community-common 和 mysql-community-libs-compat 软件包以获得功能性的标准 MySQL 安装。要执行此类标准的基本安装,请转至包含所有这些软件包的文件夹(最好不要有类似名称的其他 RPM 软件包),然后发出以下命令:In most cases, you need to install the mysql-community-server, mysql-community-client, mysql-community-client-plugins, mysql-community-libs, mysql-community-icu-data-files, mysql-community-common, and mysql-community-libs-compat packages to get a functional, standard MySQL installation. To perform such a standard, basic installation, go to the folder that contains all those packages (and, preferably, no other RPM packages with similar names), and issue the following command:

$> sudo yum install mysql-community-{server,client,client-plugins,icu-data-files,common,libs}-*

将 yum 替换为 zypper(对于 SLES),以及 dnf(适用于 Fedora)。Replace yum with zypper for SLES, and with dnf for Fedora.

虽然最好使用 yum 等高级软件包管理工具来安装软件包,但喜欢直接 rpm 命令的用户可以替换 yum 使用rpm -Uvh命令安装命令;但是,使用 rpm -Uvh 会使安装过程更容易失败,因为安装过程可能会遇到潜在的依赖性问题。While it is much preferable to use a high-level package management tool like yum to install the packages, users who prefer direct rpm commands can replace the yum install command with the rpm -Uvh command; however, using rpm -Uvh instead makes the installation process more prone to failure, due to potential dependency issues the installation process might run into.

要仅安装客户端程序,您可以在要安装的软件包列表中跳过 mysql-community-server;发出以下命令:To install only the client programs, you can skip mysql-community-server in your list of packages to install; issue the following command:

$> sudo yum install mysql-community-{client,client-plugins,common,libs}-* 

将 yum 替换为 zypper(对于 SLES),以及 dnf(适用于 Fedora)。Replace yum with zypper for SLES, and with dnf for Fedora.

使用 RPM 软件包进行 MySQL 的标准安装会在系统目录下创建文件和资源,如下表所示。A standard installation of MySQL using the RPM packages result in files and resources created under the system directories, shown in the following table.

表 2.13 MySQL 开发人员专区的 Linux RPM 软件包的 MySQL 安装布局Table 2.13 MySQL Installation Layout for Linux RPM Packages from the MySQL Developer Zone

文件或资源Files or Resources 位置Location
客户端程序和脚本Client programs and scripts /usr/bin/usr/bin
mysqld 服务器mysqld server /usr/sbin/usr/sbin
配置文件Configuration file /etc/my.cnf/etc/my.cnf
数据目录Data directory /var/lib/mysql/var/lib/mysql
错误日志文件Error log file

对于 RHEL、Oracle Linux、CentOS 或 Fedora 平台:/var/log/mysqld.logFor RHEL, Oracle Linux, CentOS or Fedora platforms: /var/log/mysqld.log

对于 SLES:/var/log/mysql/mysqld.logFor SLES: /var/log/mysql/mysqld.log

secure_file_privValue of secure_file_priv /var/lib/mysql-files/var/lib/mysql-files
System V init 脚本System V init script

的值 RHEL、Oracle Linux、CentOS 或 Fedora 平台:/etc/init.d/mysqldFor RHEL, Oracle Linux, CentOS or Fedora platforms: /etc/init.d/mysqld

对于 SLES:/etc/init.d/mysqlFor SLES: /etc/init.d/mysql

Systemd 服务Systemd service

对于 RHEL、Oracle Linux、CentOS 或 Fedora 平台:mysqldFor RHEL, Oracle Linux, CentOS or Fedora platforms: mysqld

对于 SLES:mysqlFor SLES: mysql

Pid 文件Pid file /var/run/mysql/mysqld.pid /var/run/mysql/mysqld.pid
SocketSocket /var/lib/mysql/mysql.sock/var/lib/mysql/mysql.sock
密钥环目录Keyring directory /var/lib/mysql-keyring/var/lib/mysql-keyring
Unix 手册页Unix manual pages /usr/share/man/usr/share/man
包含(标题)文件Include (header) files /usr/include/mysql/usr/include/mysql
库Libraries /usr/lib/mysql/usr/lib/mysql
其他支持文件(例如,错误消息和字符集)文件)Miscellaneous support files (for example, error messages, and character set files) /usr/share/mysql/usr/share/mysql

安装还会在系统上创建一个名为 mysql 的用户和一个名为 mysql 的组。The installation also creates a user named mysql and a group named mysql on the system.

Notes
  • mysql 用户是使用 -r 和 -s /bin/false 选项创建的useradd 命令,使其没有服务器主机的登录权限(有关详细信息,请参阅创建 mysql 用户和组)。要切换到操作系统上的 mysql 用户,请使用 su 命令的 --shell=/bin/bash 选项:The mysql user is created using the -r and -s /bin/false options of the useradd command, so that it does not have login permissions to your server host (see Creating the mysql User and Group for details). To switch to the mysql user on your OS, use the --shell=/bin/bash option for the su command:

    $> su - mysql --shell=/bin/bash
    

  • 使用旧软件包安装以前版本的 MySQL 可能会创建一个名为 /usr/my.cnf 的配置文件。强烈建议您检查该文件的内容并将所需的设置迁移到 /etc/my.cnf 文件中,然后删除 /usr/my.cnf。Installation of previous versions of MySQL using older packages might have created a configuration file named /usr/my.cnf. It is highly recommended that you examine the contents of the file and migrate the desired settings inside to the file /etc/my.cnf file, then remove /usr/my.cnf.

MySQL 在安装过程结束时不会自动启动。对于 Red Hat Enterprise Linux、Oracle Linux、CentOS 和 Fedora 系统,使用以下命令启动 MySQL:MySQL is NOT automatically started at the end of the installation process. For Red Hat Enterprise Linux, Oracle Linux, CentOS, and Fedora systems, use the following command to start MySQL:

$> systemctl start mysqld

对于 SLES 系统,命令相同,但服务名称不同:For SLES systems, the command is the same, but the service name is different:

$> systemctl start mysql

如果操作系统启用了 systemd,则使用标准 systemctl(或者使用参数 service)反转)命令,例如 stop、start、status 和 restart 应该用于管理 MySQL 服务器服务。 mysqld 服务默认启用,并在系统重新启动时启动。请注意,某些事情在 systemd 平台上可能会有所不同:例如,更改数据目录的位置可能会导致问题。有关详细信息,请参阅第 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. Notice that certain things might work differently on systemd platforms: for example, changing the location of the data directory might cause issues. See Section 2.5.9, “Managing MySQL Server with systemd” for additional information.

在使用 RPM 和 DEB 软件包进行升级安装期间,如果升级时 MySQL 服务器正在运行,则 MySQL 服务器将停止,升级将发生,然后重新启动 MySQL 服务器。一个例外:如果升级过程中版本也发生变化(例如从社区到商业,反之亦然),则 MySQL 服务器不会重新启动。During an upgrade installation using RPM and DEB packages, if the MySQL server is running when the upgrade occurs then the MySQL server is stopped, the upgrade occurs, and the MySQL server is restarted. One exception: if the edition also changes during an upgrade (such as community to commercial, or vice-versa), then MySQL server is not restarted.

在服务器初始启动时,假设服务器的数据目录为空,会发生以下情况: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 证书和密钥文件。An SSL certificate and key files are generated in the data directory.

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

  • 超级用户帐户'root'@'localhost'已创建。设置超级用户的密码并将其存储在错误日志文件中。要显示它,请对 RHEL、Oracle Linux、CentOS 和 Fedora 系统使用以下命令: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 for RHEL, Oracle Linux, CentOS, and Fedora systems:

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

    对 SLES 系统使用以下命令:Use the following command for SLES systems:

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

    下一步是使用生成的临时密码登录并为超级用户帐户设置自定义密码:The next step is to log 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.

如果安装过程中出现问题,您可能会在错误日志文件中找到调试信息 /var/log/mysqld.log。If something goes wrong during installation, you might find debug information in the error log file /var/log/mysqld.log.

对于某些 Linux 发行版,可能需要增加 mysqld 可用的文件描述符数量限制。请参阅第 B.3.2.16 节“文件未找到和类似错误”For some Linux distributions, it might be necessary to increase the limit on number of file descriptors available to mysqld. See Section B.3.2.16, “File Not Found and Similar Errors”

从多个 MySQL 版本安装客户端库。 可以安装多个客户端库版本,例如您希望保持与链接到先前库的旧应用程序的兼容性的情况。要安装较旧的客户端库,请使用 --oldpackage 选项和 rpm。例如,要在具有 MySQL 8.0 的 libmysqlclient.21 的 EL6 系统上安装 mysql-community-libs-5.5,请使用如下命令:Installing Client Libraries from Multiple MySQL Versions.  It is possible to install multiple client library versions, such as for the case that you want to maintain compatibility with older applications linked against previous libraries. To install an older client library, use the --oldpackage option with rpm. For example, to install mysql-community-libs-5.5 on an EL6 system that has libmysqlclient.21 from MySQL 8.0, use a command like this:

$> rpm --oldpackage -ivh mysql-community-libs-5.5.50-2.el6.x86_64.rpm

调试包。 使用调试包编译的 MySQL Server 的特殊变体已包含在服务器 RPM 包中。它执行调试和内存分配检查,并在服务器运行时生成跟踪文件。要使用该调试版本,请使用 /usr/sbin/mysqld-debug 启动 MySQL,而不是将其作为服务启动或使用 /usr/sbin/mysqld 启动。有关可以使用的调试选项,请参阅第 7.9.4 节“DBUG 包”。Debug Package.  A special variant of MySQL Server compiled with the debug package has been included in the server RPM packages. It performs debugging and memory allocation checks and produces a trace file when the server is running. To use that debug version, start MySQL with /usr/sbin/mysqld-debug, instead of starting it as a service or with /usr/sbin/mysqld. See Section 7.9.4, “The DBUG Package” for the debug options you can use.

Note

默认插件目录为 /usr/lib64/mysql/plugin/debug 并可使用 plugin_dir。The default plugin directory is /usr/lib64/mysql/plugin/debug and is configurable with plugin_dir.

从源 SRPM 重建 RPM。 MySQL 的源代码 SRPM 包可供下载。它们可以按原样使用标准 rpmbuild 工具链重建 MySQL RPM。Rebuilding RPMs from source SRPMs.  Source code SRPM packages for MySQL are available for download. They can be used as-is to rebuild the MySQL RPMs with the standard rpmbuild tool chain.