MySQL添加账户

6.3.2 Adding User Accounts 添加账户

After connecting to the server as root, you can add new accounts. The following example uses CREATE USER and GRANT statements to set up four accounts:

使用root用户登陆后可以添加账户。下面的例子使用 create usergrant statements 来建立四个账户。

mysql >CREATE USER 'finley'@'localhost' IDENTIFIED BY 'password';
mysql >GRANT ALL PRIVILEGES ON *.* TO 'finley'@'localhost'
->    WITH GRANT OPTION;
mysql >CREATE USER 'finley'@'%' IDENTIFIED BY 'password';
mysql >GRANT ALL PRIVILEGES ON *.* TO 'finley'@'%'
->    WITH GRANT OPTION;
mysql >CREATE USER 'admin'@'localhost' IDENTIFIED BY 'password';
mysql >GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';
mysql >CREATE USER 'dummy'@'localhost';

The accounts created by those statements have the following properties:

使用以上statements创建的账户有以下性质:

  • Two accounts have a user name of finley. Both are superuser accounts with full privileges to do anything. The ‘finley’@‘localhost’ account can be used only when connecting from the local host. The ‘finley’@’%’ account uses the ‘%’ wildcard for the host part, so it can be used to connect from any host.

    有两个用户的名字是“finely”。他们都是超级用户,拥有做任何事的权利。“finley’@‘localhost”账户在本地连接时使用。“finley’@’%”账户使用通配符 % 来表示主机,所以他可以在任何主机上使用。

    The ‘finley’@‘localhost’ account is necessary if there is an anonymous-user account for localhost. Without the ‘finley’@‘localhost’ account, that anonymous-user account takes precedence when finley connects from the local host and finley is treated as an anonymous user. The reason for this is that the anonymous-user account has a more specific Host column value than the ‘finley’@’%’ account and thus comes earlier in the user table sort order. (user table sorting is discussed in Section 6.2.6, “Access Control, Stage 1: Connection Verification”.)

    如果本地主机上有一个匿名用户账户,那么 “finley’@‘localhost” 账户的存在就很重要了。在没有 “finley’@‘localhost” 账户的情况下,如果finley在本地主机上连接时会被视为一个匿名用户,并优先使用匿名用户账户。原因是匿名用户帐户的主机列值比 “finley’@’%” 帐户更specific,因此在用户表排序顺序中出现得更早。(用户表的排序介绍见6.2.6节,“Access Control, Stage 1: Connection Verification”。)

  • The ‘admin’@‘localhost’ account can be used only by admin to connect from the local host. It is granted the RELOAD and PROCESS administrative privileges. These privileges enable the admin user to execute the mysqladmin reload, mysqladmin refresh, and mysqladmin flush-xxx commands, as well as mysqladmin processlist . No privileges are granted for accessing any databases. You could add such privileges using GRANT statements.

    “admin’@'localhost” 账户仅允许管理员(admin)在本地进行连接。他被赋予了 RELOADPROCESS 管理权。这些权力允许管理员执行mysqladmin reload。mysqladmin refresh 和 mysqladmin flush-xxx等命令,还有 mysqladmin processlist 。连接数据库的权力并没有被赋予。你可以使用 grant statements 来加上这些权力。

  • The ‘dummy’@‘localhost’ account has no password (which is insecure and not recommended). This account can be used only to connect from the local host. No privileges are granted. It is assumed that you will grant specific privileges to the account using GRANT statements.

    “dummy’@'localhost” 账户没有密码(这是不安全的,不推荐这么做)。这个账户仅允许从本地主机连接。没有赋予任何权力。在之后,你可以使用 grant statements 为它赋予权力。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值