在 Windows 上,你可以使用普通用户帐户将服务器作为 Windows 服务运行。On Windows, you can run the server as a Windows service using a normal user account.
在 Linux 上,对于使用 MySQL 仓库或 RPM 包进行的安装,MySQL 服务器 mysqld 应该由本地 mysql 操作系统用户启动。通过其他操作系统用户启动是不被 MySQL 仓库包含的初始化脚本支持的。On Linux, for installations performed using a MySQL repository or
RPM packages, the MySQL server mysqld should be
started by the local mysql operating system
user. Starting by another operating system user is not supported
by the init scripts that are included as part of the MySQL
repositories.
在 Unix(或使用 tar.gz 包安装的 Linux)上,MySQL 服务器 mysqld 可以由任何用户启动和运行。然而,出于安全原因,你应该避免以 Unix root 用户身份运行服务器。要将 mysqld 更改为以普通无特权的 Unix 用户 user_name 运行,必须执行以下操作:On Unix (or Linux for installations performed using
tar.gz packages) , the MySQL server
mysqld can be started and run by any user.
However, you should avoid running the server as the Unix
root user for security reasons. To change
mysqld to run as a normal unprivileged Unix
user user_name, you must do the
following:
如果服务器正在运行,请先停止它(使用 mysqladmin shutdown)。Stop the server if it is running (use mysqladmin shutdown).
更改数据库目录和文件,使
user_name具有读取和写入其中文件的权限(您可能需要以 Unixroot用户身份执行此操作):Change the database directories and files so thatuser_namehas privileges to read and write files in them (you might need to do this as the Unixrootuser):$>
chown -Ruser_name/path/to/mysql/datadir如果不这样做,当服务器以
user_name身份运行时,将无法访问数据库或表。If you do not do this, the server cannot access databases or tables when it runs asuser_name.如果 MySQL 数据目录中的目录或文件是符号链接,
chown -R可能不会为您跟随符号链接。如果没有,您也必须跟随这些链接并更改它们所指向的目录和文件。If directories or files within the MySQL data directory are symbolic links,chown -Rmight not follow symbolic links for you. If it does not, you must also follow those links and change the directories and files they point to.以用户
user_name启动服务器。另一种方法是以 Unixroot用户身份启动 mysqld,并使用--user=选项。mysqld 启动后,会在接受任何连接之前切换为以 Unix 用户user_nameuser_name运行。Start the server as useruser_name. Another alternative is to start mysqld as the Unixrootuser and use the--user=option. mysqld starts, then switches to run as the Unix useruser_nameuser_namebefore accepting any connections.要在系统启动时自动以指定用户启动服务器,请通过在
/etc/my.cnf配置文件或服务器数据目录中的my.cnf配置文件的[mysqld]组中添加user选项来指定用户名。例如:To start the server as the given user automatically at system startup time, specify the user name by adding auseroption to the[mysqld]group of the/etc/my.cnfoption file or themy.cnfoption file in the server's data directory. For example:[mysqld] user=
user_name
如果您的 Unix 机器本身未被安全保护,您应该为授权表中的 MySQL root 账户设置密码。否则,任何拥有该机器登录账户的用户都可以使用 mysql 客户端并使用 --user=root 选项执行任意操作。(无论如何,为 MySQL 账户设置密码都是一个好主意,尤其是在服务器上存在其他登录账户时。)参见 第 2.9.4 节,“保护初始 MySQL 账户”。If your Unix machine itself is not secured, you should assign
passwords to the MySQL root account in the
grant tables. Otherwise, any user with a login account on that
machine can run the mysql client with a
--user=root option and perform any
operation. (It is a good idea to assign passwords to MySQL
accounts in any case, but especially so when other login accounts
exist on the server host.) See
Section 2.9.4, “Securing the Initial MySQL Account”.