MySQL数据库-备份

数据的备份还原

导出:先对数据库进行备份,然后提取备份文件中的sql语句

导入:

方法一:创建和原始数据库同名的数据库,然后从备份文件中导出sql语句(此方法不需要修改导出的sql语句);

方法二:在数据库中直接运行导出的sql语句(需要修改数据库文件)

简单查询

查询的格式

select 查询的内容 from 表名 where 条件

注:表示查询内容的方法

*:表示任意的任意字符

一个字段的名字时:表示查询一个字段

多个字段时:多个字段之间用逗号表示分割

where条件写法

>        大于

案例:select * from students where age>20

>=      大于等于

案例:select * from students where age>=20

<        小于

案例:select * from students where age,20

<=      小于等于

案例:select * from students where age,=20

<>      不等于

案例:select * from students where age<>20

!=      不等于

案例:select * from students where age!>20

between .... and ....        判断范围

案例:select * from students where age between 20 and 30

is null        是空

案例:select * from students where age is null

is not null        不是空

案例:select * from students where age is not null

like        模糊查询

案例:select * from students where name like 'r%'

in           判断某个字段是否在给定的集合中

案例:select * from students where age  in(15,23,36)

通配符:%

表示任意多个的任意字符

组合条件的方法:

and:多个条件同时满足

案例:select * from students where age<20 and age>30

or:多个条件中满足其中一个

案例:select * from students where age=20 or age=22 or age=25

排序

select 查询内容 from 表名 where 条件 order by 字段名

order by 字段名:根据指定的字段进行排序

asc:升序(默认升序)

desc:降序

指定输出几条数据

格式:select 查询内容 from 表名 where 条件 order by 字段名 limit 数字

默认输出所有符合条件的记录

指定输出:limit 数字

聚合函数

sum()        求和

avg()        求平均值

max()       求最大值

min()        求最小值

count()      统计记录条数

去重

distinct

案例:select distinct from students

去掉相同的值

分组

group by

案例:按照班级分组,并且统计各个班级有多少人
select count(*),classid from students group by classid

分组后加条件

having

格式: select 字段 from 表名 group by 字段 having 条件

查询进阶

链接查询:将两张后多张表联合起来进行查询,这种查询叫做链接查询

交叉链接:

表中的每一行分别于其他表中的每一行组成新的行

新表的行数是两个表的行数相乘,列数是两个表的列数相乘

自然链接:

将多个表中,符合条件的进行链接

外链接:左外链接、右外链接

交叉链接

select * from 表名1,表名2

会得到一个笛卡尔积表,这个表中存在着大量的无用数据

自然链接

在交叉链接的基础上,通过加条件,可以得到自然链接

格式:select * from 表名1,表名2 where 表名1.字段=表名2.字段

相关推荐

  1. mysql数据库备份命令

    2024-04-23 12:12:02       38 阅读
  2. mysql数据库备份恢复

    2024-04-23 12:12:02       18 阅读
  3. MySQL数据库-备份

    2024-04-23 12:12:02       16 阅读
  4. 定时备份mysql数据库

    2024-04-23 12:12:02       12 阅读
  5. 【4】MySQL数据库-备份

    2024-04-23 12:12:02       8 阅读
  6. MySQL数据备份

    2024-04-23 12:12:02       41 阅读
  7. MySQL数据备份

    2024-04-23 12:12:02       30 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-23 12:12:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-23 12:12:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-23 12:12:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-23 12:12:02       18 阅读

热门阅读

  1. 单例模式(设计模式)

    2024-04-23 12:12:02       14 阅读
  2. Python 监控程序的内存占用量

    2024-04-23 12:12:02       13 阅读
  3. 哪家券商有快速通道?

    2024-04-23 12:12:02       11 阅读
  4. 算法稳定币是未来趋势?

    2024-04-23 12:12:02       14 阅读