当前位置:首页 > 数据库 > MySql > 正文内容

mysql学习笔记20211119

有云转晴2年前 (2021-11-19)MySql7740

mysql学习笔记20211119

用户管理 权限设置

进入root账户创建一个普通用户

1.创建一个用户名为‘yyds’密码为‘1234’的用户

create user 'yyds'@'localhost' identified by '1234';

'yyds'@'localhost'  用户名(只能在本地主机上登录操作)

'yyds'@'%'          用户名 (能够在所有的主机上进行登录)

2.查看对应用户权限

show grants for 'yyds'@'localhost';

权限为

GRANT USAGE ON *.* TO 'yyds'@'localhost'  登录权限

权限分为两部分,一个是那个用户的权限,二是针对于哪个操作对象的权限。

3.给用户‘yyds’授予权限

 授予数据库访问权限

grant create on a.* to 'yyds'@'localhost';

回收数据库访问权限

revoke create on a.* from 'yyds'@'localhost';

4.

(1)表格创建权限

grant create on a.emp to 'yyds'@'localhost';

回收表格创建权限

revoke create on a.emp from 'yyds'@'localhost';

(2)表格查询权限

grant select on a.emp to 'yyds'@'localhost';

回收表格查询权限

revoke select on a.emp from 'yyds'@'localhost';

5.  

 表格添加权限

grant insert on a.emp to 'yyds'@'localhost';

  回收表格添加权限

revoke insert on a.emp from 'yyds'@'localhost';


grant on to   (授权)

revoke on from(回收)


6.delete from emp;                   删除数据

drop table emp;      删除表

grant delete on a.emp to 'yyzq'@'localhost';
grant drop on a.emp to 'yyzq'@'localhost';

7.update emp set 列名='值'

grant update on a.emp to 'yyds'@'localhost';


8.增删改查


对列的操作

(1):alter table 表名 add column 列名 类型;增加列

(2):alter table 表名 drop  column 列名; 删除列

(3):alter table 表名 change column 旧列名 新列名 数据类型; 更改列名

          alter table 表名 change column 列名 列名 新数据类型      更改数据类型

(4):desc 表名;    查看列

(5):alter table 表名 rename to 新表名;更改表名

(6):alter table 表名 drop primary key;删除主键

不建议后面对表进行大幅度修改,否则可能会导致数据丢失



例子:

create table abc(id varchar(100),name varchar(100));

mysql学习笔记20211119

alter table abc add column sex varchar(100);

mysql学习笔记20211119

alter table abc drop column sex;

mysql学习笔记20211119

alter table abc change column id sex varchar(100);

mysql学习笔记20211119

alter table abc change column sex sex varchar(20);

mysql学习笔记20211119


(5)alter table 旧表名 rename to 新表名;

(6)alter table 表名 drop primary key;    删除主键

主键 外键


primary key auto_increment
create table abc1(id int primary key auto_increment); 
alter table abc1 drop primary key;


9.

grant alter on a.emp to 'yyzq'@'localhost';

    赋予yyzq的alter所有权限        

alter跟数据的增删改查没关系

10.

访问谋个表的权限

grant create user on *.* to 'yyzq'@'localhost';

  给用户‘yyzq’创建用户的权限

*.*  全局权限

11

grant reload on *.* to 'yyzq'@'localhost';
flush privileges;   reload权限

  刷新权限表


12.

grant create on lyl.* to 'yyzq'@'localhost' with grant option;

授予用户“将自己权限授予另一个用户”的权限


例如


root                             

 grant create on lyl.* to 'yyzq'@'localhost' with grant option;

yyzq    

grant create on lyl.* to 'yy0'@'localhost';

         yy0用户已经存在

grant create on lyl.* to 'yy0'@'localhost' identified by '1234';    不存在

yy0                use lyl;









































mysql学习笔记20211119  您阅读本篇文章共花了: 

分享到:

    扫描二维码推送至手机访问。

    版权声明:本文由有云转晴发布,如需转载请注明出处。

    本文链接:https://www.yyzq.cf/?id=13

    标签: mysql
    分享给朋友:
    返回列表

    上一篇:mysql学习笔记20211118

    没有最新的文章了...

    发表评论

    访客

    ◎欢迎参与讨论,请在这里发表您的看法和观点。