MySQL创建用户与授权【彩民之家高手论坛】

2019-11-21 20:19 来源:未知

命令:

SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');

假若是当下登录客商用:

SET PASSWORD = PASSWORD("newpassword");

例子:

SET PASSWORD FOR 'pig'@'%' = PASSWORD("123456");

注意:

用上述命令授权的顾客不可能给其余客户授权,假如想让该客商能够授权,用以下命令:

GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;

风华正茂. 开立顾客

说明:

privilege, databasename, tablename:同授权部分

命令:

CREATE USER 'username'@'host' IDENTIFIED BY 'password';

命令:

DROP USER 'username'@'host';

 

说明:

  • username:你将开创的顾客名
  • host:钦点该客商在哪些主机上得以登录,假如是本地客商可用localhost,倘使想让该顾客能够从随机远程主机登入,能够选用通配符%
  • password:该顾客的登入密码,密码可感觉空,假设为空则该客商可以无需密码登入服务器

说明:

  • privileges:顾客的操作权限,如SELECTINSERTUPDATE等,假若要授予所的权力则应用ALL
  • databasename:数据库名
  • tablename:表名,假如要付与该顾客对具备数据库和表的呼应操作权限则可用*表示,如*.*

三.设置与改观顾客密码

四. 撤消客商权限

例子:

CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
CREATE USER 'pig'@'192.168.1.101_' IDENDIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '';
CREATE USER 'pig'@'%';

命令:

REVOKE privilege ON databasename.tablename FROM 'username'@'host';

例子:

GRANT SELECT, INSERT ON test.user TO 'pig'@'%';
GRANT ALL ON *.* TO 'pig'@'%';
GRANT ALL ON maindataplus.* TO 'pig'@'%';

命令:

GRANT privileges ON databasename.tablename TO 'username'@'host'

例子:

REVOKE SELECT ON *.* FROM 'pig'@'%';

二. 授权:

MySQL创建用户与授权【彩民之家高手论坛】。五.剔除顾客

注意:

即令你在给顾客'pig'@'%'授权的时候是这么的(或看似的卡塔尔:GRANT SELECT ON test.user TO 'pig'@'%',则在选取REVOKE SELECT ON *.* FROM 'pig'@'%';命令并无法收回该客商对test数据库中user表的SELECT 操作。相反,假使授权使用的是GRANT SELECT ON *.* TO 'pig'@'%';REVOKE SELECT ON test.user FROM 'pig'@'%';命令也无法收回该客商对test数据库中user表的Select权限。

切实消息能够用命令SHOW GRANTS FOR 'pig'@'%'; 查看。

TAG标签:
版权声明:本文由彩民之家高手论坛发布于彩民之家高手论坛,转载请注明出处:MySQL创建用户与授权【彩民之家高手论坛】