6.2.1 Account User Names and Passwords帐户用户名和密码

MySQL stores accounts in the user table of the mysql system database. MySQL将user存储在MySQL系统数据库的user表中。An account is defined in terms of a user name and the client host or hosts from which the user can connect to the server. 帐户是根据用户名和用户可以从中连接到服务器的一个或多个客户端主机来定义的。For information about account representation in the user table, see Section 6.2.3, “Grant Tables”.有关user表中帐户表示的信息,请参阅第6.2.3节“授权表”

An account may also have authentication credentials such as a password. 帐户还可以具有身份验证凭据,例如密码。The credentials are handled by the account authentication plugin. 凭据由帐户身份验证插件处理。MySQL supports multiple authentication plugins. MySQL支持多个身份验证插件。Some of them use built-in authentication methods, whereas others enable authentication using external authentication methods. 其中一些使用内置的身份验证方法,而另一些使用外部身份验证方法启用身份验证。See Section 6.2.17, “Pluggable Authentication”.请参阅第6.2.17节“可插入身份验证”

There are several distinctions between the way user names and passwords are used by MySQL and your operating system:MySQL和您的操作系统使用用户名和密码的方式有几个区别:

The MySQL installation process populates the grant tables with an initial root account, as described in Section 2.10.4, “Securing the Initial MySQL Account”, which also discusses how to assign a password to it. MySQL安装过程使用初始root帐户填充授权表,如第2.10.4节“保护初始MySQL帐户”所述,该节还讨论了如何为其分配密码。Thereafter, you normally set up, modify, and remove MySQL accounts using statements such as CREATE USER, DROP USER, GRANT, and REVOKE. 此后,通常使用CREATE USERDROP USERGRANTREVOKE等语句来设置、修改和删除MySQL帐户。See Section 6.2.8, “Adding Accounts, Assigning Privileges, and Dropping Accounts”, and Section 13.7.1, “Account Management Statements”.请参阅第6.2.8节“添加帐户、分配权限和删除帐户”第13.7.1节“帐户管理报表”

To connect to a MySQL server with a command-line client, specify user name and password options as necessary for the account that you want to use:要使用命令行客户端连接到MySQL服务器,请根据需要为要使用的帐户指定用户名和密码选项:

shell> mysql --user=finley --password db_name

If you prefer short options, the command looks like this:如果您喜欢短选项,则命令如下所示:

shell> mysql -u finley -p db_name

If you omit the password value following the --password or -p option on the command line (as just shown), the client prompts for one. 如果省略命令行上--password-p选项后面的密码值(如图所示),则客户端会提示输入一个密码值。Alternatively, the password can be specified on the command line:或者,可以在命令行中指定密码:

shell> mysql --user=finley --password=password db_name
shell> mysql -u finley -ppassword db_name

If you use the -p option, there must be no space between -p and the following password value.如果使用-p选项,则-p和后面跟随的密码值之间不能有空格。

Specifying a password on the command line should be considered insecure. 在命令行上指定密码应该被认为是不安全的。See Section 6.1.2.1, “End-User Guidelines for Password Security”. 参见第6.1.2.1节“密码安全的最终用户指南”To avoid giving the password on the command line, use an option file or a login path file. 要避免在命令行上提供密码,请使用选项文件或登录路径文件。See Section 4.2.2.2, “Using Option Files”, and Section 4.6.7, “mysql_config_editor — MySQL Configuration Utility”.请参阅第4.2.2.2节“使用选项文件”第4.6.7节“mysql_config_editor——MySQL配置实用工具”

For additional information about specifying user names, passwords, and other connection parameters, see Section 4.2.4, “Connecting to the MySQL Server Using Command Options”.有关指定用户名、密码和其他连接参数的更多信息,请参阅第4.2.4节“使用命令选项连接到MySQL服务器”