UPDATE
修改
update user set age=28 where id=1;
一定要有表达式,否则严重错误
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165019201-1260171480.png)
DELETE
删除
delete from user where id=1; 指定删除某一行
delete from user; 表里内容彻底请客
truncate table user; 处理大量数据效率高,用时更少
SELECT
加载数据
wget 'https://codeload.github.com/datacharmer/test_db/zip/master' -O master.zip
执行导入
mysql -u root -p <employees.sql
加载成功之后,可以查看到具体的数据库的信息
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165132733-538037249.png)
MySQL查询
基本查询数据
全表查询
select * from user;
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165214883-1707519546.png)
查询部分字段
select name from user; 查询表内名字
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165227073-883783950.png)
计数
select count(*) from user; 查询表内有多少数据
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165240343-1625150366.png)
select count(1) from user; 查询表内多少数据(效率更高一些,适用于数据量较大的)
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165251537-327435984.png)
条件过滤
并且(AND)
select * from user where name="ghj" and age=18;
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165310566-1829587569.png)
或者(OR)
select * from user where name="ghj" or age=20;
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165323823-381401076.png)
包含(IN)
select * from user where name in ("ghj","lisi");
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165338329-719721738.png)
范围检查(BETWEEN AND)
select * from user where age between 18 and 20;
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165351136-1223343324.png)
否定结果(NOT)
select * from user where name not in ("ghj","lisi");
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165413340-1831787373.png)
select * from user where age not between 18 and 20;
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165425188-1934852865.png)
匹配任意字符(%)
select * from user where name like 'g%';
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165442295-1336087628.png)
以什么为开头(^)
select * from user where name rlike '^g';
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165456581-886201533.png)
以什么为结束($)
select * from user where user rlike 'si$';
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165509681-1736895817.png)
使用别名(AS)
select count(1) as count from user;
![](/i/l/?n=22&i=blog/2939582/202208/2939582-20220824165522123-467715103.png)
搜索
复制
标签:name,age,查询,user,MySQL,where,select From: https://www.cnblogs.com/Aurora--1/p/16620788.html