On Windows, you can run the server as a Windows service using a normal user account.在Windows上,您可以使用普通用户帐户将服务器作为Windows服务运行。
On Linux, for installations performed using a MySQL repository or RPM packages, the MySQL server mysqld should be started by the local 在Linux上,对于使用MySQL存储库或RPM包执行的安装,MySQL服务器mysqld应由本地mysql
operating system user. mysql
操作系统用户启动。Starting by another operating system user is not supported by the init scripts that are included as part of the MySQL repositories.MySQL存储库中包含的init脚本不支持由其他操作系统用户启动。
On Unix (or Linux for installations performed using 在Unix(或使用tar.gz
packages) , the MySQL server mysqld can be started and run by any user. tar.gz
包执行安装的Linux)上,MySQL服务器mysqld可以由任何用户启动和运行。However, you should avoid running the server as the Unix 但是,出于安全原因,您应该避免以Unixroot
user for security reasons. root
用户身份运行服务器。To change mysqld to run as a normal unprivileged Unix user 要将mysqld更改为以普通的无特权Unix用户user_name
, you must do the following:user_name
运行,您必须执行以下操作:
Stop the server if it is running (use mysqladmin shutdown).如果服务器正在运行,请停止它(使用mysqladmin关机)。
Change the database directories and files so that 更改数据库目录和文件,以便user_name
has privileges to read and write files in them (you might need to do this as the Unix root
user):user_name
具有读取和写入其中文件的权限(您可能需要以Unix root
用户的身份执行此操作):
shell> chown -R user_name
/path/to/mysql/datadir
If you do not do this, the server cannot access databases or tables when it runs as 如果不这样做,服务器在以user_name
.user_name
运行时将无法访问数据库或表。
If directories or files within the MySQL data directory are symbolic links, 如果MySQL数据目录中的目录或文件是符号链接,chown -R
might 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.chown -R
可能不会跟在符号链接后面。如果没有,您还必须遵循这些链接并更改它们指向的目录和文件。
Start the server as user 以用户user_name
. Another alternative is to start mysqld as the Unix root
user and use the --user=
option. user_name
user_name
身份启动服务器。另一种选择是以Unix root
用户身份启动mysqld,并使用--user=user_name
选项。mysqld starts, then switches to run as the Unix user mysqld启动,然后在接受任何连接之前切换为以Unix用户user_name
before accepting any connections.user_name
运行。
To start the server as the given user automatically at system startup time, specify the user name by adding a 要在系统启动时以给定用户身份自动启动服务器,请通过在服务器数据目录中的user
option to the [mysqld]
group of the /etc/my.cnf
option file or the my.cnf
option file in the server's data directory. For example:/etc/my.cnf
选项文件或my.cnf
选件文件的[mysqld]组中添加用户选项来指定用户名。例如:
[mysqld]
user=user_name
If your Unix machine itself is not secured, you should assign passwords to the MySQL 如果你的Unix机器本身不安全,你应该在授权表中为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选项运行mysql客户端并执行任何操作。--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.)(在任何情况下,为MySQL帐户分配密码都是一个好主意,尤其是当服务器主机上存在其他登录帐户时。) See Section 2.10.4, “Securing the Initial MySQL Account”.请参阅第2.10.4节,“保护初始MySQL帐户”。