mysql的sql语句
1、dml语句增删改
1.1为表内添加数据
对应插入:insert into 表名 (字段1,字段2,.....) value(值1,值2........)
 整体插入:insert into 表名 values(值1,值2........)
1.2删除表内数据
delete  from  表名    where  条件
例:delete  from  tb  where   id=1
 
解析:将tb表中id=1的数据记录条删除
1.3修改表内数据
update  表名 set  字段=值   where 条件
例:update  tb  set  name='小红'  where  id=1
 
解析:将满足条件 id=1 的数据记录的 name字段 修改成小红
2、dql查询语句
查询表内数据
单个条件查询
select   *  from   表名  where   条件
例:select  *  from  tb  where  id=1
解析:查询tb表中id字段等于1的数据记录,*等于所有字段
 
多个条件查询
select  *  from    表名  where  条件1  [and,or]并列和或   条件2  .........
例:select   * from  tb  where   name='m'  and  age>20;
解析:将tb表中满足名字为m且年龄大于20的信息显示
多条件查询的运算符:>  <    >=    <=   =    !=
 
关键字between and查询
例:select  * from  tb  where  salary    between   3000  and  6000
解析:将表tb中salary薪水字段满足3000到6000之间的输出(注意:包括3000和6000)
这条语句等价于select    * from  tb  where  salary>=3000  and  salary<=6000
 
关键字In的集合查询
select  * from  表名  where  字段  in (值1,值2.........)
例:select  * from   tb  where   salary  in (3000,6000,8000)
解析:将表tb中salary字段满足3000,6000,8000的数据记录显示
反推:select  * from   tb  where   salary  not in (3000,6000,8000)
 
关键字 is null
select  * from  表名 where  字段   is null
解析:将该表内指定字段为空的数据记录条显示
反推select  * from  表名 where  字段   is  not null
 
模糊查询
select  * from  表名  where  字段  like(像)   '某某_'
解析:将该表中字段为某某某的显示
_:代表一个字符
%:代表匹配多个字符
 
排序查询
升序:select  *   from  表名   order  by  字段  asc
降序  select * from  表名   order  by  字段   desc
 
*MySQL默认是按升序,所以asc可写可不写效果也一样
排序后进行筛选
select  * from   表名 order  by  字段  desc     limit  数值(前几)
 
2、dcl数据库控制语言
用来设置数据库用户或角色的权限等
创建MySQL用户
1、不加密创建:create  user  用户名@'登入地址'   identified  by   '密码'
2、加密创建:create user  用户名@'登入地址'   identified  by    password('密码'):通过password对密码进行哈希密文加密
 
登入地址:指定IP地址、localhost本地IP登入、%任意主机登入
 注意:当远程登入数据库发现登入不上可以考虑是否登入地址是否给定
数据库的权限给予
grant   权限列表   on  对象   to  用户@'主机地址'
 
权限列表:all代表所有权限,insert代表插入权限,update代表更新权限等等…
 对象:可以是数据库,表,字段 *.*代表任何库下的任何表、数据库.*代表该数据库下的所有表、数据库.表 代表该数据库下的该表
 解析:权限列表给到哪个用户作用于哪个对象
数据库权限的收回
revoke   权限列表  on  对象    from   用户@'主机地址'  










