数据库:专门存放数据的电子仓库,提供用户获取数据;
关系型数据库:关系型数据库是以行列的方式存在表中(list)中表格式的存储方式
,它可以提供表与表之间进行协助存储。
非关系型数据库:非关系型存储形式是以键值对的形式进行存储数据,前面是键后面是值
{'name';123456}
数据的信息表现方式和载体:文字信息,符号,数字,语言,图像,视频;
关系型数据库:mysql,db2,oracle,sqlwerver,
是以行列的方式存储在表中(表格式存储方式),可以提供表与表之间进行协助存储;
非关系型数据库:hbase(列模型),redis(键值对模型),mongodb(文档类模型)
mysql特点:开源免费;体积小安装简单,维护成本低;c++编写;支持多系统;
登入mysql系统:mysql -u root -p(密文登录);mysql -u root -p'123456'(明文登录)
service mysqld start 启动数据库
service mysqld
show databases; 查看当前数据库;
create database 数据库名; 创建数据库
use 数据库名; 进入数据库;
show tables; 查看当前数据库的表;
drop database 数据库名; 删除数据库;
创建表:
create table wuhan3(id int(4)primary key autoincrement,phone bigint(10)default 13510951238,name varchar(10),class float(20,2)not null,time date);
desc 表名; 查看表的数据结构;
select * from 表名; 查看表;
insert into wuhan3(id,phone,class,time)values(1,13400000000,1999.123,‘2021-06-09’); 添加数据;
alter table wuhan3 change id si_d int(4);(change自动删除自增长);
alter table wuhan3 change si_d si_d int(4)auto_inrement;(添加自增长);
alter table wuhan3 add age int(4);添加字段;
alter table wuhan3 add age int(4)after class;添加字段到class之后;
alter table wuhan3 add int(4)first;添加字段到最前面;
alter table wuhan3 modify cheshi1 int(4)after cehsi2;调整字段位置
alter table wuhan3 drop cheshi3;删除字段;
alter table wuhan3 drop ceshi4,drop ceshi5;删除多个字段;
delete from wuhan3 where time=‘2021-08-08’;删除数据
alter table wuhan3 drop primary key;删除主键约束
ialter table wuhan3 change id id int(4)primary key;增加主键
数据类型:
数值型:int 表示整数,存储范围大小正负2147483647,超过则用bigint;
float 浮点数类型,(a,b)前面表示存储字节大小,后面表示默认小数点位数;
字符型:char:固定长度的存储方式,数据给固定的存储大小空间;
varvhar:可变长度存储方式,
日期类型:date
修改表字段的操作用change:修改表字段之后,会自动删除自增长
增加表字段使用add:
调整字段的顺序:modify;
drop 对表结构进行操作:
常见的约束类型:
primary key :主键约束;(这个字段具有唯一性,不能重复)
auto_ increment :自增长约束;(默认在前面一个值的基础+1)
not null :非空约束;(这个字段添加内容时不能为空)
default :默认值约束:(这个字段未添加则添加提前设置好的默认内容,如果添加内容则不会使用默认值)
foreign key :外键约束;
数据库的作用:
1.测试过程中,我们需要大量的测试数据,就需要我们会数据的操作指令进行造测试数据;
2.后面做接口测试以及UI自动化性能测试,都会用到数据库;
mysql 的查询语句:
select * from 表名 查询所有的
select id from 表名 查询特定的字段
[img=408,0]C:\Users\Administrator\AppData\Local\YNote\data\weixinobU7VjsbxbWEkv3tNwZpX2Hvki5Y\1c2c442394fa43b3a920f94b0029b95d\co[g)9nxpwl_clbe({97n@f.jpg[/img]
select *from 表名 where+条件(查询区间范围的值)
C:\Users\Administrator\AppData\Local\YNote\data\weixinobU7VjsbxbWEkv3tNwZpX2Hvki5Y\28f5eb258c7749e3aeb0a4dc860f0618\ih7@aap80birr5$e0}u2l_j.jpg
select name from wuhan3;
select name, id from wuhan3;
select id from wuhan3 where id=4;
select id from wuhan3 where id=4 or id=5;
mysql的查询语句:
select*from 表名,
* 通配符,所有的
select id from 表名 查询特定要求的字段
where 条件语句
select id from wuhan3 where id=5;
or 与 and 且
= <= >= !=
等于 小于等于 大于等于 不等于
in属于
select*from wuhan3 where id in (2,6); 查询wuhan3中所有id属于2和6的值
not in已不属于
select*from wuhan3 where id not in (2,6); 查询wuhan3中除了id值2和6以外的所有数据
is null 查询为空的数据
is not null 查询不为空的数据
[img=354,0]C:\Users\Administrator\AppData\Local\YNote\data\weixinobU7VjsbxbWEkv3tNwZpX2Hvki5Y\154f10c9bfed4ccb991c6e166c760806\33zmnp6$45gd[~weiey8s8h.jpg[/img]
select*from wuhan3 where name not is null; 查询wuhan3中name字段中不为空的数据
select*from wuhan3 where name is null; 查询wuhan3中name字段中为空的数据
update 修改表数据的时候,一定要注意加修改的条件,不然就会全部进行修改。
mysql 聚合函数
count;sum;max;min ,avg,distinct
mysql 重装出错的原因,
第一 删除方式有问题,没有卸载mysql程序,rm删除的时候没有删除干净mysql的配置文件,从而导致再次安装时候出错。
order by 排序查看用
asc 升序
desc 降序
group by 一般是接聚合函数使用,不能和分组以外的字段结合使用,那么接其他字段他不会报错,但是会造成数据混乱。
group by 后面不能接where使用,如果要接查询条件的话用having进行接条件,having的作用相当于where
备份,只是备份表结构,并不会备份表数据
create table wuhan4 like wuhan3; 备份一个像表wuhan3一样的表wuhan4;
备份一个数据库,进行还原时,sql文件还原到某一个数据当中,所以还原时,须新建一个数据库进行还原。
权限
usage 代表没有权限
all 代表所有的权限
select 字段 from 数据表; 查询单个字段
select id from wuhan3; 查询wuhan3中id字段的数据
select name, id from wuhan3; 查询wuhan3 中name和id 这两个字段的内容
select id from wuhan3 where id=5; 查询wuhan3中条件为id=5的id 字段的内容
select id from wuhan3 where id=5 or id=7; 查询wuhan3中id=5与id=7的数据
select*from wuhan3 where id=5 or class=111; 查询wuhan3中所有id=5与class=111的数据
select*from wuhan3 where id=1 and max=999; 查询wuhan3中所有id字段=5与max字段=999的数据
select*from wuhan3 where time >='2021-01-01'and time <='2021-06-09'; 查询wuhan3中所有time值范围为(2021-01-01~2021-06-09)的数据
select*from wuhan3 where time between '2021-01-01'<=2021-06-09'; 查询wuhan3中所有time值范围为(2021-01-01~2021-06-09)的数据
select*from wuhan3 where id in(2,3); 查询wuhan3中id值为 2和3的数据
select*from wuhan3 where name is null; 查询wuhan3中name字段为空的数据
select*from wuhan3 where name is not null; 查询wuhan3 中name字段不为空的数据
查询某个字段模糊匹配的数据
例:select*from wuhan3 where phone like '135%'; 查询wuhan3 中含有134 并且能和phone字段匹配的数据
select*from wuhan3 where id limit 2,2; 查询从第二行开始,再查询两行的数据
修改特定字段的信息
例: update wuhan3 set phone=13500000000 where id=1; 修改wuhan3中id=1的phone字段的信息
默认修改所有字段的信息
例 update wuhan3 set phone=13500000000; 默认修改wwuhan3中所有phone字段的信息
select count(*) from wuhan3; 统计wuhan3中字段的数量
select sum(id) from wuhan3; 查看wuhan3中id值的和
select max(id) from wuhan3; 查看wuhan3中id值的最大值
select min(id) from wuhan3; 查看wuhan3中id值的最小值
select name,min(id) from wuhan3; 查询wuhan3中id为最小值和id为最小值时name的名字
select avg(id) from wuhan3; 查看wuhan3中id的平均值
select distinct(phone) from wuhan3; 查看去掉phone字段中重复数据的内容
select max(phone) as a from wuhan3; 查看wuhan3中phone字段的最大值取一个别名a显示
select*from (select max(phone) as a from wuhan3)t where a =13500000000;取别名查看
select*from wuhan3 order by id desc; 查询wuhan3中id字段中的数据从大到小排序
select*from wuhan3 order by id asc; 查询wuhan3中id字段内容从小到大排序
select*from wuhan3 group by avg; 查看wuhan3中按avg字段分组所有内容;(包含所有字段)
select avg wuhan3 group by avg; 查看wuhan3中按avg字段分组的内容;(只有avg字段)
select avg from wuhan3 group by avg having avg=100; 查看wuhan3中按照avg进行的分组中avg=100的内容
group by 后面不能接where;
select avg,count(*) as b from wuhan3 group by avg; 查看wuhan3中按照avg进行分组的统计数量取别名b显示
select avg,count(*) as b from wuhan3 group by avg having b>=2;
creat table wuhan4 like wuhan3; 备份一个和wuhan3相同数据结构的表wuhan4
insert into wuhan4(avg,phone,id) select avg,phone,id from wuhan3; 把武汉3这个表中数据特定字段的值添加到新表wuhan4中
insert into wuhan4 select*from wuhan3; 把wuhan3中所有的数据添加到wuhan4中;
1.在根目录下执行
mysqldump -uroot -p123456 wuhan3>/wuhan3.sql 备份一个wuhan3.sql 数据库放在根目录下面
2.在mysql中执行
create database wuhan6; 新建一个数据库wuhan3
3.在根目录下执行
mysql -uroot -p123456 wuhan6</wuhan3.sql 还原备份的数据库内容
C:\Users\Administrator\AppData\Local\YNote\data\weixinobU7VjsbxbWEkv3tNwZpX2Hvki5Y\37b7f61d3d444f14ab6957abbec2379c\1079.png
C:\Users\Administrator\AppData\Local\YNote\data\weixinobU7VjsbxbWEkv3tNwZpX2Hvki5Y\56a136a01c2c4358b86c9082cbf05671\1077.png
C:\Users\Administrator\AppData\Local\YNote\data\weixinobU7VjsbxbWEkv3tNwZpX2Hvki5Y\8e6edf7a3d1643d58c9f444e0417bc51\1075.png
C:\Users\Administrator\AppData\Local\YNote\data\weixinobU7VjsbxbWEkv3tNwZpX2Hvki5Y\f266573650fe4cf5bfe0761b89aacd39\1073.png
C:\Users\Administrator\AppData\Local\YNote\data\weixinobU7VjsbxbWEkv3tNwZpX2Hvki5Y\cb26368fa67f41ed91ef1af28542f8b6\1069.png
insert into user(host,user,password) values('localhost','ergouzi',password('123456'))
增加一个mysql用户名为ergouzi
flush privileges; 刷新权限
在根目录下执行:mysql -uergouzi -p123456 进入ergouzi用户
在msql用户中更改ergouzi的权限
grant select,delete on *.* to'ergouzi'@'localhost' identdfied by '123456';
增加ergouzi用户select和delete的权限
grant all on *.* to'ergouzi'@'localhost' identdfied by '123456';
增加ergouzi用户的所有权限
在ergouzi用户中查看
show grants for 'ergouzi'@'localhost'; 查看当前用户的权限
usage 代表没有权限
all 代表所有的权限
% 远程连接
C:\Users\Administrator\AppData\Local\YNote\data\weixinobU7VjsbxbWEkv3tNwZpX2Hvki5Y\59cec9c901cf48b9862505859394aaf3\1060.png
show databases; 显示有哪些数据库
desc +表名; 查看表结构
show tables; 查看有哪些表
select*from +表名; 查看表中所有数据_
|
|