加入收藏 | 设为首页 | 会员中心 | 我要投稿 南通站长网 (https://www.0513zz.cn/)- 专有云、图像技术、经验、数据治理、专属主机!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

Mysql之DCL数据控制语言

发布时间:2022-08-09 12:39:12 所属栏目:MySql教程 来源:互联网
导读:Mysql DCL数据控制语言 数据控制语言(DCL:Data Control Language)是用来设置或者更改数据库用户或角色权限的语句,这些语句包括GRANT、DENY、REVOKE等语句 限制root用户指定ip登录 查看root用户可以在哪台机器登录 select user,host from mysql.user wher
  Mysql
  DCL数据控制语言
  数据控制语言(DCL:Data Control Language)是用来设置或者更改数据库用户或角色权限的语句,这些语句包括GRANT、DENY、REVOKE等语句
 
  限制root用户指定ip登录
  查看root用户可以在哪台机器登录
 
  select user,host from mysql.user where user='root';
 
  +------+-----------+
  | user | host      |
  +------+-----------+
  | root | %         |
  | root | localhost |
  +------+-----------+
  1
  2
  3
  4
  5
  6
  7
  8
  修改mysql库里边的user表
 
   update mysql.user set host='localhost' where user='root';
  1
  刷新权限
 
  flush privileges;
  1
  用户密码
  修改用户密码分三种方法:
 
  第一种
  // set password for 用户@ip = password('密码');
  set password for root@localhost = password('root');
  1
  2
  第二种
  // mysqladmin -u用户 -p旧密码 password 新密码;
  mysqladmin -urootmysqladmin -uroot -proot password;
  1
  2
  第三种
  update mysql.user set authentication_string=password('root') where user='root' and host='localhost';
  1
  忘记密码
 
  第一步
  修改配置文件my.cnf (默认在/etc/my.cnf),在[mysqld]下面加上 skip-grant-tables (跳过权限的意思)
 
  第二步
  重启mysql服务
 
  第三步
  mysql -uroot -p 无需密码登录进入
 
  第四步
  修改密码
 
  创建新用户并限制ip网段登录
  创建用户的语法
 
  create user 'username'@'host' identified by 'password';
  1
  username:你将创建的用户名 ​ host:指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost,如果想让该用户可以从任意远程主机 登陆,可以使用通配符% ​ password:该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器
 
  创建用户语法
 
  创建一个mitday用户,并指定登录密码:123456,可以在任何一台远程主机都可以登录
 
  create user 'mitday'@'%' identified by '123456';
  1
  创建一个mitday用户,并指定登录密码:为空,指定在120网段的机器登录
 
  create user 'mitday'@'120.%.%.%' identified by '';
  1
  查看权限
 
  select * from mysql.user where user='mitday';
   
  show grants for 'mitday'@'%';
 
  /* USAGE:无权限的意思 */
  +------------------------------------+
  | Grants for mitday@%                |
  +------------------------------------+
  | GRANT USAGE ON *.* TO 'mitday'@'%' |
  +------------------------------------+
 
 
 
  show grants for 'root'@'localhost';
 
  /* WITH GRANT OPTION:表示这个用户拥有grant权限,即可以对其他用户授权 */
  +---------------------------------------------------------------------+
  | Grants for root@localhost                                           |
  +---------------------------------------------------------------------+
  | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
  | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION        |
  +---------------------------------------------------------------------+
   删除用户语法
 
  // drop user 'username'@'host';
  drop user 'mitday'@'%';
  delete from mysql.user where user = 'mitday';
  1
  2
  3
  库表权限授权与回收
  授权语法
  grant 权限1,权限2..... on 数据库对象 to '用户'@'host' identified by 'password';

(编辑:南通站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读