8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 2 安装 MySQL / 2.8 从源安装 MySQL / 2.8.4 使用标准源发行版安装 MySQL
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

2.8.4 使用标准源发行版安装 MySQL2.8.4 Installing MySQL Using a Standard Source Distribution

从标准安装 MySQL 源代码分发:To install MySQL from a standard source distribution:

  1. 验证您的系统是否满足第 2.8.2 节“源代码安装先决条件”中列出的工具要求。Verify that your system satisfies the tool requirements listed at Section 2.8.2, “Source Installation Prerequisites”.

  2. 使用第 2.1.3 节“如何获取 MySQL”。Obtain a distribution file using the instructions in Section 2.1.3, “How to Get MySQL”.

  3. 按照本节中的说明配置、构建和安装发行版。Configure, build, and install the distribution using the instructions in this section.

  4. 按照第 2.9 节“安装后设置和测试”中的说明执行安装后过程。Perform postinstallation procedures using the instructions in Section 2.9, “Postinstallation Setup and Testing”.

MySQL 使用 CMake 作为所有平台上的构建框架。此处给出的说明应该使您能够进行有效的安装。有关使用 CMake 构建 MySQL 的更多信息,请参阅如何使用 CMake 构建 MySQL 服务器。MySQL uses CMake as the build framework on all platforms. The instructions given here should enable you to produce a working installation. For additional information on using CMake to build MySQL, see How to Build MySQL Server with CMake.

如果您从源 RPM 启动,请使用以下命令制作可以安装的二进制 RPM。如果您没有 rpmbuild,请使用 rpm。If you start from a source RPM, use the following command to make a binary RPM that you can install. If you do not have rpmbuild, use rpm instead.

$> rpmbuild --rebuild --clean MySQL-VERSION.src.rpm

结果是您按照部分中的指示安装一个或多个二进制 RPM 软件包 2.5.4,“使用 Oracle 的 RPM 软件包在 Linux 上安装 MySQL”。The result is one or more binary RPM packages that you install as indicated in Section 2.5.4, “Installing MySQL on Linux Using RPM Packages from Oracle”.

从压缩 tar 文件或 Zip 存档源分发版安装的顺序与从通用二进制分发版安装的过程类似(请参阅部分 2.2,“使用通用二进制文件在 Unix/Linux 上安装 MySQL”),不同之处在于它适用于所有平台,并且包括配置和编译发行版的步骤。例如,对于 Unix 上的压缩 tar 文件源代码分发,基本安装命令序列如下所示:The sequence for installation from a compressed tar file or Zip archive source distribution is similar to the process for installing from a generic binary distribution (see Section 2.2, “Installing MySQL on Unix/Linux Using Generic Binaries”), except that it is used on all platforms and includes steps to configure and compile the distribution. For example, with a compressed tar file source distribution on Unix, the basic installation command sequence looks like this:

# Preconfiguration setup
$> groupadd mysql
$> useradd -r -g mysql -s /bin/false mysql
# Beginning of source-build specific instructions
$> tar zxvf mysql-VERSION.tar.gz
$> cd mysql-VERSION
$> mkdir bld
$> cd bld
$> cmake ..
$> make
$> make install
# End of source-build specific instructions
# Postinstallation setup
$> cd /usr/local/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

下面显示了源代码构建特定说明的更详细版本。A more detailed version of the source-build specific instructions is shown following.

Note

此处显示的过程不会为 MySQL 帐户设置任何密码。执行完该过程后,请继续执行第 2.9 节“安装后设置和测试”,进行安装后设置和测试。The procedure shown here does not set up any passwords for MySQL accounts. After following the procedure, proceed to Section 2.9, “Postinstallation Setup and Testing”, for postinstallation setup and testing.

执行预配置设置Perform Preconfiguration Setup

在 Unix 上,设置 mysql拥有数据库目录并用于运行和执行 MySQL 服务器的用户,以及该用户所属的组。详细信息请参见创建 mysql 用户和组。然后以 mysql 用户身份执行以下步骤,除非另有说明。On Unix, set up the mysql user that owns the database directory and that should be used to run and execute the MySQL server, and the group to which this user belongs. For details, see Create a mysql User and Group. Then perform the following steps as the mysql user, except as noted.

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

选择要解压发行版的目录并更改其中的位置。Pick the directory under which you want to unpack the distribution and change location into it.

使用第 2.1.3 节“如何获取 MySQL”。Obtain a distribution file using the instructions in Section 2.1.3, “How to Get MySQL”.

将发行版解压到当前目录:Unpack the distribution into the current directory:

  • 要解压压缩的 tar 文件,tar 可以解压缩并解压发行版(如果它有 z 选项)支持:To unpack a compressed tar file, tar can decompress and unpack the distribution if it has z option support:

    $> tar zxvf mysql-VERSION.tar.gz
    

    如果您的 tar 没有 z 选项支持,请使用 gunzip 解压发行版并使用 tar 解压它:If your tar does not have z option support, use gunzip to decompress the distribution and tar to unpack it:

    $> gunzip < mysql-VERSION.tar.gz | tar xvf -
    

    或者,CMake 可以解压和解压分发包:Alternatively, CMake can decompress and unpack the distribution:

    $> cmake -E tar zxvf mysql-VERSION.tar.gz
    
  • 要解压 Zip 存档,请使用 WinZip 或其他可以读取 .zip 文件的工具。To unpack a Zip archive, use WinZip or another tool that can read .zip files.

解包分发文件会创建一个名为 mysql-VERSION。Unpacking the distribution file creates a directory named mysql-VERSION.

配置发行版Configure the Distribution

将位置更改为解压发行版的顶级目录:Change location into the top-level directory of the unpacked distribution:

$> cd mysql-VERSION

在源代码树之外构建以保持树干净。如果当前工作目录下的顶级源目录名为mysql-src,则可以在同级的名为build的目录中构建。创建目录并转到那里:Build outside of the source tree to keep the tree clean. If the top-level source directory is named mysql-src under your current working directory, you can build in a directory named build at the same level. Create the directory and go there:

$> mkdir bld
$> cd bld

配置构建目录。最低配置命令不包含覆盖配置默认值的选项:Configure the build directory. The minimum configuration command includes no options to override configuration defaults:

$> cmake ../mysql-src

构建目录不必位于源代码树之外。例如,您可以在顶级源代码树下名为 build 的目录中进行构建。为此,从 mysql-src 作为当前工作目录开始,创建目录 build,然后转到该目录:The build directory need not be outside the source tree. For example, you can build in a directory named build under the top-level source tree. To do this, starting with mysql-src as your current working directory, create the directory build and then go there:

$> mkdir build
$> cd build

配置构建目录。最低配置命令不包含覆盖配置默认值的选项:Configure the build directory. The minimum configuration command includes no options to override configuration defaults:

$> cmake ..

如果您在同一级别有多个源代码树(例如,要构建 MySQL 的多个版本),则第二种策略可能更有利。第一个策略将所有构建目录置于同一级别,这要求您为每个目录选择唯一的名称。使用第二种策略,您可以对每个源树中的构建目录使用相同的名称。以下说明采用第二种策略。If you have multiple source trees at the same level (for example, to build multiple versions of MySQL), the second strategy can be advantageous. The first strategy places all build directories at the same level, which requires that you choose a unique name for each. With the second strategy, you can use the same name for the build directory within each source tree. The following instructions assume this second strategy.

在 Windows 上,指定开发环境。例如,以下命令分别将 MySQL 配置为 32 位或 64 位构建:On Windows, specify the development environment. For example, the following commands configure MySQL for 32-bit or 64-bit builds, respectively:

$> cmake .. -G "Visual Studio 12 2013"

$> cmake .. -G "Visual Studio 12 2013 Win64"

在 macOS 上,使用 Xcode IDE:On macOS, to use the Xcode IDE:

$> cmake .. -G Xcode

运行 Cmake 时,您可能需要向命令行添加选项。以下是一些示例:When you run Cmake, you might want to add options to the command line. Here are some examples:

有关更详细的选项列表,请参阅第 2.8.7 节“MySQL 源配置”选项”。For a more extensive list of options, see Section 2.8.7, “MySQL Source-Configuration Options”.

要列出配置选项,请使用以下命令之一:To list the configuration options, use one of the following commands:

$> cmake .. -L   # overview

$> cmake .. -LH  # overview with help text

$> cmake .. -LAH # all params with help text

$> ccmake ..     # interactive display

如果 CMake 失败,您可能需要使用不同的选项再次运行它来重新配置。如果您确实要重新配置,请注意以下事项:If CMake fails, you might need to reconfigure by running it again with different options. If you do reconfigure, take note of the following:

  • 如果 CMake 在先前运行之后运行,则它可能会使用在先前调用期间收集的信息。此信息存储在 CMakeCache.txt 中。当 CMake 启动时,它会查找该文件并读取其内容(如果存在),并假设该信息仍然正确。当您重新配置时,该假设无效。If CMake is run after it has previously been run, it may use information that was gathered during its previous invocation. This information is stored in CMakeCache.txt. When CMake starts, it looks for that file and reads its contents if it exists, on the assumption that the information is still correct. That assumption is invalid when you reconfigure.

  • 每次运行 CMake 时,都必须再次运行 ma​​ke 进行重新编译。但是,您可能希望首先从以前的版本中删除旧的对象文件,因为它们是使用不同的配置选项进行编译的。Each time you run CMake, you must run make again to recompile. However, you may want to remove old object files from previous builds first because they were compiled using different configuration options.

要防止使用旧的对象文件或配置信息,请在重新运行 CMake 之前在 Unix 上的构建目录中运行这些命令:To prevent old object files or configuration information from being used, run these commands in the build directory on Unix before re-running CMake:

$> make clean
$> rm CMakeCache.txt

或者,在 Windows 上:Or, on Windows:

$> devenv MySQL.sln /clean
$> del CMakeCache.txt

在询问 MySQL Community Slack,检查 CMakeFiles 目录中的文件以获取有关失败的有用信息。要提交错误报告,请按照第 1.6 节“如何报告错误或问题”中的说明进行操作。Before asking on the MySQL Community Slack, check the files in the CMakeFiles directory for useful information about the failure. To file a bug report, please use the instructions in Section 1.6, “How to Report Bugs or Problems”.

构建发行版Build the Distribution

在 Unix 上:On Unix:

$> make
$> make VERBOSE=1

第二个命令集 VERBOSE 显示每个编译源的命令。The second command sets VERBOSE to show the commands for each compiled source.

在使用 GNU make 的系统上使用 gmake,并且它已安装为 gmake。Use gmake instead on systems where you are using GNU make and it has been installed as gmake.

在 Windows 上:On Windows:

$> devenv MySQL.sln /build RelWithDebInfo

如果您已进入编译阶段,但发行版尚未构建,请参阅第 2.8.8 节“处理编译 MySQL 的问题”寻求帮助。如果这不能解决问题,请按照第 1.6 节“如何报告错误或问题”中给出的说明将其输入我们的错误数据库。如果您安装了所需工具的最新版本,并且它们在尝试处理我们的配置文件时崩溃,也请报告这一情况。但是,如果您遇到 command not found 错误或所需工具的类似问题,请不要报告它。相反,请确保安装了所有必需的工具,并且正确设置了 PATH 变量,以便 shell 可以找到它们。If you have gotten to the compilation stage, but the distribution does not build, see Section 2.8.8, “Dealing with Problems Compiling MySQL”, for help. If that does not solve the problem, please enter it into our bugs database using the instructions given in Section 1.6, “How to Report Bugs or Problems”. If you have installed the latest versions of the required tools, and they crash trying to process our configuration files, please report that also. However, if you get a command not found error or a similar problem for required tools, do not report it. Instead, make sure that all the required tools are installed and that your PATH variable is set correctly so that your shell can find them.

安装分发版Install the Distribution

在 Unix 上:On Unix:

$> make install

这会将文件安装在配置的安装目录下(默认情况下为 /usr/local/mysql)。您可能需要以 root 身份运行该命令。This installs the files under the configured installation directory (by default, /usr/local/mysql). You might need to run the command as root.

要在特定目录中安装,请在命令行中添加 DESTDIR 参数:To install in a specific directory, add a DESTDIR parameter to the command line:

$> make install DESTDIR="/opt/mysql"

或者,生成可安装在您喜欢的位置的安装包文件:Alternatively, generate installation package files that you can install where you like:

$> make package

此操作会生成一个或多个可像通用二进制分发包一样安装的 .tar.gz 文件。请参阅第 2.2 节“使用通用二进制文件在 Unix/Linux 上安装 MySQL”。如果您使用 -DCPACK_MONOLITHIC_INSTALL=1 运行 CMake,则该操作会生成单个文件。否则,它会生成多个文件。This operation produces one or more .tar.gz files that can be installed like generic binary distribution packages. See Section 2.2, “Installing MySQL on Unix/Linux Using Generic Binaries”. If you run CMake with -DCPACK_MONOLITHIC_INSTALL=1, the operation produces a single file. Otherwise, it produces multiple files.

在 Windows 上,生成数据目录,然后创建 .zip 存档安装包:On Windows, generate the data directory, then create a .zip archive installation package:

$> devenv MySQL.sln /build RelWithDebInfo /project initial_database
$> devenv MySQL.sln /build RelWithDebInfo /project package

您可以将生成的 .zip 存档安装在您喜欢的位置。请参阅第 2.3.3 节“配置:手动”。You can install the resulting .zip archive where you like. See Section 2.3.3, “Configuration: Manually”.

执行安装后设置Perform Postinstallation Setup

安装过程的其余部分包括设置配置文件、创建核心数据库和启动 MySQL 服务器。有关说明,请参阅第 2.9 节“安装后设置和测试”。The remainder of the installation process involves setting up the configuration file, creating the core databases, and starting the MySQL server. For instructions, see Section 2.9, “Postinstallation Setup and Testing”.

Note

MySQL 授权表中列出的帐户最初没有密码。启动服务器后,您应该按照第 2.9 节“安装后设置和测试”中的说明为其设置密码。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.9, “Postinstallation Setup and Testing”.