DML-操控-数据的操作包括使用
insert //数据的插入
delete //数据的删除
update //数据的更新
完整插入
insert into 表名 values(所需要插入的内容 ‘,’ 隔开)字符需用‘’隔开
部分插入
insert into 表名 (列名,列名) values(值1,值2)
更新数据
update 表名 set 列名= 值 where condition
更改MySQL密码
update user set authentication_string=password(‘qianfeng@123’) where user=‘root’
password()密码加密
更新密码后需刷新数据库密码生效
flush privileges
删除数据
delete from 表名 (删除表内所有内容)
delete from 表名 where id=1 (删除某一项)
DQL-查询
select //查询操作
简单查询
select * from 表名 (查询所有列)
select 列名 from 表名 (查询部分列)
四则运算查询,通过加减乘除取得自己想要得到的结果(例如通过月薪*12得出年薪)
单条件查询
where //哪里
select name.age from 表名 where age=20 (查询表中所有年龄为20的人)
多条件查询
and //并且
select name.age from 表名 where age=20 and name=like ‘z%’ (查询表中所有年龄为20并且名字为z开头的人 %参考模糊查询)
or //或
select name.age from 表名 where age=20 or age=21((查询表中所有年龄为20和21的人)
between and //在什么之间
select name.age from 表名 where age between 20 and 25(查询表中所有年龄为20到25的人)
not between and //不在什么之间age
select name.age from 表名 where age not between 20 and 25(查询表中所有年龄不在20到25的人)
in //集合查询
select name.age from 表名 where age in(20,21,22) (查询年龄在20,21,22的人)
not in //排除查询
select name.age from 表名 where age not in(20,21,22) (查询年龄不在20,21,22的人)
is null //空值查询
select name.age from 表名 where age is null (找出所有没有填写年龄的人)
like‘%’ //模糊查询(通配符%代表多个任意字符)
select name.age from 表名 where name=like ‘z%’ (模糊查找,姓名为‘z’开头的人
查询排序
order by //查询结果排序
select * from 表名 order by age (查看表中年龄的排序)
desc //降序
select * from 表名 order by age desc(降序查看表中年龄的排序)
ASC //升序
select * from 表名 order by age asc(升序查看表中年龄的排序)
limit //限制,只看
select * from 表名 order by age desc limit 5(降序查看表中年龄最大的五个人的排序)