找回密码
 立即注册
  • 便民服务
  • 关注我们
  • 社区新手

mysql的单表查询,数据库和表的备份

[复制链接]
truncate 表名  
delete  from 表名 :删除数据,可以恢复,在日志中查看

查询 ===》select
不等于:!= 、<>

select * from test;
select id,name from test;
select id,name from test where phone="13712341234";
select * from test where name!="xiaoli";    查询name不等于“xiaoli”的数据
select * from test where name<>"xiaoli";   查询name不等于“xiaoli”的数据


select * from test where name="xiaoli"and class="6班"; 查询姓名为xiaoli且班级是6班的学生数据

select * from test where name = "xiaoli" or name="laowang"  查询满足任意一个条件的数据

select * from test where id between 2 and 5;

select * from test where id in (1,2,3,4,5);  查询id满足集合中条件时的数据

select * from test where (id,name) in ((1,"xiaozhou"),(2,"xiaoli"),3,4,5);  查询多条件满足集合中数据时的结果

select * from test where id not in (1,4);

selec * from test where class is null;        为空时的数据

select * from test where class is not null;  不为空时的数据

select * from test where name like "xiao%";

select * from test where class="9班" limit 1,3; =====》limit 下标 ,数据行数

排序
select * from test order by asc; 升序
select * from test oder by desc; 降序

分组
select * from test group by class; 分组    ,使用group by 时前面的显示字段不能包含分组字段以外的字段(显示的是查到的第一条数据)

count(*) ,---统计
sum(字段),----对某个字段,求和
avg(),-----平均数
max,---最大值
min,-----最小值
distinct(字段)----给字段去重
select sum(id),avg(id),max(id),min(id), count(*) from test;
select distinct id from test;

备份表数据

create table 新表 like 需要备份的表;=====》备份表结构
insert into 新表 select * from 需要备份的表;====》备份表数据
注意点:
1.插入的表必须存在
2.插入的表必须没有数据

备份库
mysqldump -uroot -p654321 zwy > /zwy/zwy.sql ====》将库数据备份到指定目录下

mysql -uroot -p654321 zwy_bak

注意点:
1.插入的库必须存在
2.在linux下执行命令


分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册