DCL作用,给mysql用户授权及回收权限
1、给用户授权
create user root@'192.168.32.%' identified by '123'; grant all on *.* to root@'192.168.32.%' ; create user ywx@'192.168.32.%' identified by '123'; grant update,select,delete,insert on wordpress.* to ywx@'192.168.32.%';
revoke delete on wordpress.* from ywx@'192.168.32.%';
DML作用:对表中的数据行进行增、删、改
1、插入数据insert
(1) 最标准的insert语句 INSERT INTO 表明(列名1,列名2,列名3,。。。) VALUES(列1内容,列2内容,列3内容。。。) 案列 INSERT INTO stu(id,sname,sage,sg,sfz,intime) VALUES (1,'zs',18,'m','123456',NOW()); --- 省事的写法(不建议) INSERT INTO stu VALUES (2,'ls',18,'m','1234567',NOW()); (2)查询 SELECT * FROM stu; (3)针对性的录入数据 INSERT INTO stu(sname,sfz) VALUES ('w5','34445788'); (4)同时录入多行数据 INSERT INTO stu(sname,sfz) VALUES ('w55','3444578d8'), ('m6','1212313'), ('aa','123213123123'); SELECT * FROM stu;
DESC stu; SELECT * FROM stu; UPDATE stu SET sname='zhao4' WHERE id=2; #把id=2的sname改为zhao4 注意:update语句必须要加where。 如果不加where条件语句 UPDATE stu SET sname='zhao4'; #是把stu表整个sname列的数据改为zhao4
DELETE FROM stu where id=2; #把id=2的行删除(逻辑删除,不释放空间,会造成数据页的不连续)
全表删除:
DELETE FROM stu
truncate table stu;
区别:
delete: DML操作, 是逻辑性质删除,逐行进行删除,速度慢.
truncate: DDL操作,对与表段中的数据页进行清空,速度快.
#1、添加state状态列 ALTER TABLE stu ADD state TINYINT NOT NULL DEFAULT 1; #2、查看state列添加成功 SELECT * FROM stu; #3、UPDATE代替delete UPDATE stu SET state=0 WHERE id=5; #4、业务语句查询 SELECT * FROM stu WHERE state=1;