OceanBase CREATE USER
描述
该语句用于创建新的 OceanBase 用户。创建新用户后,可以使用该用户连接 OceanBase。
说明
必须拥有全局的 CREATE USER 权限,才可以使用 CREATE USER 命令。
格式
create_user_stmt:
CREATE USER [IF NOT EXISTS] user_name [IDENTIFIED BY 'password'];
alter_user_stmt:
ALTER USER user_name ACCOUNT {LOCK | UNLOCK};
| ALTER USER user_name IDENTIFIED BY 'password';
| SET PASSWORD [FOR user_name] = PASSWORD('password');
| RENAME USER rename_user_action_list;
drop_user_stmt:
DROP USER user_name_list;
rename_user_action_list:
rename_user_action [, rename_user_action ...]
rename_user_action:
user_name TO user_name
user_name_list:
user_name [, user_name ...]
password:
STR_VALUE
CREATE USER [IF NOT EXISTS] user_specification_list;
user_specification_list:
user_specification [, user_specification ...]
user_specification:
user IDENTIFIED BY ‘authstring’
| user IDENTIFIED BY PASSWORD ‘hashstring’
参数解释
参数 |
描述 |
---|---|
user_name |
用户名,新建用户后,“mysql.user”表会新增一行该用户的表项。如果同名用户已经存在,则报错。 |
IDENTIFIED BY |
使用自选的 IDENTIFIED BY 子句,可以为账户给定一个密码。 |
user_name [, user_name ...] |
同时创建多个用户时,用“,”隔开。 |
user IDENTIFIED BY ‘authstring’ |
此处密码为明文,存入“mysql.user”表后,服务器端会变为密文存储下来。 |
user IDENTIFIED BY PASSWORD ‘hashstring’ |
此处密码为密文。 |
示例
- 执行以下命令创建名为 sqluser01 和 sqluser02 的用户,密码均为 123456。
CREATE USER 'sqluser01' IDENTIFIED BY '123456', 'sqluser02' IDENTIFIED BY '123456';
- 执行以下命令查看创建的用户。
SELECT user FROM mysql.user;
执行结果如下所示。
mysql> CREATE USER 'sqluser01' IDENTIFIED BY '123456', 'sqluser02' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.12 sec)
mysql> select user from mysql.user;
+-----------+
| user |
+-----------+
| root |
| admin |
| sqluser01 |
| sqluser02 |
+-----------+
4 rows in set (0.00 sec)