本节讨论启动和停止 MySQL 服务器的方法。This section discusses methods for starting and stopping the MySQL server.
通常,您启动 mysqld 服务器采用以下方式之一:Generally, you start the mysqld server in one of these ways:
直接调用mysqld。这适用于任何平台。Invoke mysqld directly. This works on any platform.
在 Windows 上,您可以设置在 Windows 启动时自动运行的 MySQL 服务。请参阅第 2.3.3.8 节“将 MySQL 作为 Windows 服务启动”。On Windows, you can set up a MySQL service that runs automatically when Windows starts. See Section 2.3.3.8, “Starting MySQL as a Windows Service”.
在 Unix 和类 Unix 系统上,您可以调用 mysqld_safe,它尝试确定mysqld的正确选项,然后使用这些选项运行它。请参阅第 6.3.2 节“mysqld_safe — MySQL 服务器启动脚本”。On Unix and Unix-like systems, you can invoke mysqld_safe, which tries to determine the proper options for mysqld and then runs it with those options. See Section 6.3.2, “mysqld_safe — MySQL Server Startup Script”.
在支持 systemd 的 Linux 系统上,您可以使用它来控制服务器。请参阅第 2.5.9 节,“使用 systemd 管理 MySQL 服务器”。On Linux systems that support systemd, you can use it to control the server. See Section 2.5.9, “Managing MySQL Server with systemd”.
在使用 System V 样式运行目录(即
/etc/init.d和运行级别特定目录)的系统上,调用 mysql.server。该脚本主要在系统启动和关闭时使用。它通常以mysql名称安装。 mysql.server 脚本通过调用 mysqld_safe。请参阅第 6.3.3 节“mysql.server — MySQL 服务器启动脚本”。On systems that use System V-style run directories (that is,/etc/init.dand run-level specific directories), invoke mysql.server. This script is used primarily at system startup and shutdown. It usually is installed under the namemysql. The mysql.server script starts the server by invoking mysqld_safe. See Section 6.3.3, “mysql.server — MySQL Server Startup Script”.在 macOS 上,安装 launchd 守护程序以在系统启动时启用 MySQL 自动启动。守护进程通过调用mysqld_safe来启动服务器。有关详细信息,请参阅第 2.4.3 节 “安装和使用 MySQL 启动守护程序”。 MySQL 首选项窗格还提供通过系统首选项启动和停止 MySQL 的控制。请参见第 2.4.4 节 “安装和使用 MySQL 首选项窗格”。On macOS, install a launchd daemon to enable automatic MySQL startup at system startup. The daemon starts the server by invoking mysqld_safe. For details, see Section 2.4.3, “Installing and Using the MySQL Launch Daemon”. A MySQL Preference Pane also provides control for starting and stopping MySQL through the System Preferences. See Section 2.4.4, “Installing and Using the MySQL Preference Pane”.
在 Solaris 上,使用服务管理框架 (SMF) 系统来启动和控制 MySQL 启动。On Solaris, use the service management framework (SMF) system to initiate and control MySQL startup.
systemd、mysqld_safe 和 mysql.server 脚本、Solaris SMF 和 macOS 启动项(或 MySQL 首选项窗格)可用于手动启动服务器,或在系统启动时自动启动服务器。 systemd、mysql.server,启动项也可用于停止服务器。systemd, the mysqld_safe and mysql.server scripts, Solaris SMF, and the macOS Startup Item (or MySQL Preference Pane) can be used to start the server manually, or automatically at system startup time. systemd, mysql.server, and the Startup Item also can be used to stop the server.
下表显示了服务器和启动脚本从选项文件中读取的选项组。The following table shows which option groups the server and startup scripts read from option files.
表 2.16 MySQL 启动脚本和支持的服务器选项组Table 2.16 MySQL Startup Scripts and Supported Server Option Groups
| 脚本Script | 选项组Option Groups |
|---|---|
| mysqldmysqld | [mysqld], [server], [mysqld-[mysqld], [server],
[mysqld- |
| mysqld_safemysqld_safe | [mysqld]、[server]、[mysqld_safe][mysqld], [server],
[mysqld_safe] |
| mysql.servermysql.server | [mysqld]、[mysql.server]、[server][mysqld], [mysql.server],
[server] |
[mysqld- 表示具有major_version][mysqld-8.3] 和 [mysqld-8.4] 等名称由版本 8.3.x、8.4.x 等的服务器读取。此功能可用于指定只能由给定版本系列中的服务器读取的选项。[mysqld-
means that groups with names like
major_version][mysqld-8.3] and
[mysqld-8.4] are read by servers
having versions 8.3.x, 8.4.x, and so
forth. This feature can be used to specify options that can be
read only by servers within a given release series.
为了向后兼容,mysql.server 还会读取 [mysql_server] 组和 mysqld_safe 还会读取 [safe_mysqld] 组。要保持最新状态,您应该更新选项文件以使用 [mysql.server] 和 [mysqld_safe] 组。For backward compatibility, mysql.server also
reads the [mysql_server] group and
mysqld_safe also reads the
[safe_mysqld] group. To be current, you should
update your option files to use the
[mysql.server] and
[mysqld_safe] groups instead.
有关 MySQL 配置文件及其结构和内容的更多信息,请参阅第 6.2.2.2 节“使用选项”文件”。For more information on MySQL configuration files and their structure and contents, see Section 6.2.2.2, “Using Option Files”.