本节介绍如何在 Unix 和类 Unix 系统上启动服务器。 (对于 Windows,请参阅第 2.3.3.5 节“首次启动服务器”。)有关可用于测试服务器是否可访问并正常工作的一些建议命令,请参阅第 2.9.3 节“测试服务器”。This section describes how start the server on Unix and Unix-like systems. (For Windows, see Section 2.3.3.5, “Starting the Server for the First Time”.) For some suggested commands that you can use to test whether the server is accessible and working properly, see Section 2.9.3, “Testing the Server”.
如果您的安装包括 mysqld_safe,请按如下方式启动 MySQL 服务器:Start the MySQL server like this if your installation includes mysqld_safe:
$> bin/mysqld_safe --user=mysql &
对于使用 RPM 软件包安装 MySQL 的 Linux 系统,服务器启动和关闭是使用 systemd 而不是 mysqld_safe 和 mysqld_safe 未安装。请参阅第 2.5.9 节,“使用 systemd 管理 MySQL 服务器”。For Linux systems on which MySQL is installed using RPM packages, server startup and shutdown is managed using systemd rather than mysqld_safe, and mysqld_safe is not installed. See Section 2.5.9, “Managing MySQL Server with systemd”.
如果您的安装包含 systemd 支持,请按如下方式启动服务器:Start the server like this if your installation includes systemd support:
$> systemctl start mysqld
如果与 mysqld 不同,则替换为适当的服务名称(例如,mysql on SLES 系统)。Substitute the appropriate service name if it differs from
mysqld (for example, mysql
on SLES systems).
使用非特权(非root)登录帐户运行 MySQL 服务器非常重要。为了确保这一点,请以 root 身份运行 mysqld_safe 并包含 --user 选项,如图所示。否则,您应该以 mysql 身份登录时执行该程序,在这种情况下,您可以在命令中省略 --user 选项。It is important that the MySQL server be run using an unprivileged
(non-root) login account. To ensure this, run
mysqld_safe as root and
include the --user option as
shown. Otherwise, you should execute the program while logged in
as mysql, in which case you can omit the
--user option from the
command.
有关以非特权用户身份运行 MySQL 的更多说明,请参阅 第 8.1.5 节,“如何以普通用户身份运行 MySQL”。For further instructions for running MySQL as an unprivileged user, see Section 8.1.5, “How to Run MySQL as a Normal User”.
如果命令立即失败并打印 mysqld
ended,请在错误日志中查找信息(默认为数据中的 文件目录)。If the command fails immediately and prints host_name.errmysqld
ended, look for information in the error log (which by
default is the
file
in the data directory).host_name.err
如果服务器无法访问它启动的数据目录或读取 mysql 架构中的授权表,它会向其错误日志写入一条消息。如果您在继续此步骤之前忽略了通过初始化数据目录来创建授权表,或者如果您运行了初始化数据目录的命令而不使用 --user 选项,则可能会出现此类问题。删除 data 目录并使用 --user 选项运行命令。If the server is unable to access the data directory it starts or
read the grant tables in the mysql schema, it
writes a message to its error log. Such problems can occur if you
neglected to create the grant tables by initializing the data
directory before proceeding to this step, or if you ran the
command that initializes the data directory without the
--user option. Remove the
data directory and run the command with the
--user option.
如果启动服务器时遇到其他问题,请参阅第 2.9.2.1 节“排除启动 MySQL 服务器的问题”。有关 mysqld_safe 的详细信息,请参阅第 6.3.2 节“mysqld_safe” — MySQL 服务器启动脚本”。有关 systemd 支持的更多信息,请参阅第 2.5.9 节 “使用 systemd 管理 MySQL 服务器”。If you have other problems starting the server, see Section 2.9.2.1, “Troubleshooting Problems Starting the MySQL Server”. For more information about mysqld_safe, see Section 6.3.2, “mysqld_safe — MySQL Server Startup Script”. For more information about systemd support, see Section 2.5.9, “Managing MySQL Server with systemd”.