因果图里面基本的符号:
恒等:两个参与比较的值相等
=是数学的表达式 一个=代表赋值 ==代表恒等
赋值10赋值给a a=10 a的具体结果就是10
非:两个参与比较的值,不一致
非的意思:否,≠,不是,不等于
或:多个选择条件,选其一种则满足条件
或的含义r
与:和的意思
与的含义:and 且&&
异:A和B只能存在一个,可以都不选择,但是不能同时存在
或:满足一项条件即可
唯一:a和b必须选,a和b的选项必须选择一个
要求:当我a存在的时候,b也要存在
强制:当我a条件存在时,b必须消失
关系型数据库:他是依靠表中字段信息内容把不同的表关联起来,所以叫关系型数据库
service mysqld restart 重启mysql服务
service mysqld start 启动MySQL服务
service mysqld stop 关闭MySQL服务
service mysqld status 查看MySQL状态
注意:只要我的虚拟机关闭,MySQL服务默认关闭,需要启动MySQL服务才能访问
访问mysql 的指令
第一种方法:MySQL -u root -p 用户名; -p password 密码
第二种方法:MySQL -u root -p"123456"
MySQL数据库的操作指令
注意:所有MySQL指令后面都需要加上;分号
show databases; 用来查询有哪些数据库
create database 创建数据库;创建数据库的名称
drop database 删除创建数据库
use +数据库名称:进入数据库指令
show tables :查看数据库当中的内容 (内容指的是数据库当中的数据表)
select user(); 查看当前的用户
select database();查看当前我在那个数据库
create table:指创建用户
=\"2021-07-01\" and time field :表中字段的名称
type:数据存储的类型
整数类型:
int 代表整数类型:id 是int 型,id这个字段他只能存储整数
最大正整数:2147483647
最大负整数:-2147483647
(4):代表储存数据的字节大小
bigint(10)也是整数类型,当你储存的值范围超过了int型就可以使用bigint
float(20,2)float 他是浮点数类型也是属于number数值类型,浮点数就是存在小数的值
(20,2) 20代表储存的字节大小;2代表保留的小数位数
字符串类型:
char 是用来存储字符;varchar 是用来储存字符
char和carchar的区别:
char是固定长度的存储大小,实际储存数值比char给的少,那么也会占满char给的储存数值
varchar:自适应长度的储存大小,实际占用大小是多少,varchar就储存多少数值
时间类型:
date:用来储存时间
mysql 数据存储类型主要有:number 数值类型,字符串类型,时间类型(date)储存时间
Null:代表当前数据是否可以为Null
null他是一个属性,yes,no代表当前存储的数据是否允许存储null这个属性
default:默认值
Extra:自增长约束
mysql当中常见的约束: 约束存储的数据
primary key:叫做唯一约束,又称主键约束,我在那个字段添加了primary key ,那个字段的值就不允许重复
key:pri 代表该段字段设置了主键
auto_increment:叫做自增长约束
id name 我当前有id和name两个字段,如果我id设置了自增从约束,我在添加值的时候没有给id增加,只给name增加内容,
default:代表默认值约束
在我没有给值的情况他会适用default所给的值,给值的情况下就会将原有的默认值更换
nuo null:非空约束 ,null代表空的意思,当前字段不能为null
select *from +表名:查询表中的数值,*代表查询所有
select phone from wuhan:只查询phone这个字段的信息
select phone,class from wuhan:查询多个字段的内容
select *from wuhan where phone=18888888:查询phone=188888888这条信息;需要用到where条件语句
select *from wuhan where name !="niuyi" :查询不包含”niuyi“的字段
select *from wuhan where time>"2020-07-01" :查询大于这个时间的字段
select * from wuhan where time<"2020-07-01" :查询小于这个时间的字段
select * from wuhan where time<=/>=”2020-07-01":大于等于或小于等于这个时间的字段
select *from wuhan where id=4 and phone =1222255455 :查询ID为4且手机号为1222255455的字段,and且的关系;
select *from wuhan where id=4 or phone =1222255455 :查询ID为4或者手机号为1222255455的字段,or与的关系
select *from wuhan where time is "null":查询所有为null的字段
select *from wuhan where time is not "null":查询所有不为null的字段
select *from wuhan where id in (1.2.3.4.5.6):查询集合内所有 id 字段
select *from wuhan where id not in (1.2.3.4.5.6):排除集合内所有id字段
berween :查询区间范围的值
select * from wh where time >="2021-07-01" and time <=“2020-07-03” :查询区间值
select *from wh where time between "2021-07-01"and“2020-07-03”:查询区间范围的值
limit:用来查询指定行数的值
select * from wh limit 2,3 :从第二行开始查询三行的内容
select *from wh where name like :"%san" %在哪里就控制匹配方向
select *from wh order by id desc:按照id降序排序 升序:asc'
聚合函数:
select max(class) from wuhan : 查看class字段里最大的值
select min(class)from wuhan:查看class字段里最小的值
select avg(class)from wuhan:求class字段里的平均值
select sum(class)from wuhan:求class字段里的和
select count(class)from wuhan:统计class字段里的行数
select distinct (name)from wuhan:去除重复的数据,使用非常多
desc :查询这个表由哪些内容构成
MySQL当中插入数据的方法
insert iernto 表名(表字段)values(对应的表数据)插入数据
~ insert into wuhan(id,name,phone,sex,class,time)values(~`~~~~~~~~):给所有字段添加值
insert into wuhan(id,~~)values(~~~~):指定字段添加值
insert into wuhan values(~~~~~~~~~~~~~~~~~~),(····················):添加多组数据,用逗号隔开;
MySQL 当中表数据结构的操作方法
alter table:操作表结构
reanme:修改表名称,更改数据库表名称
alter table 原表名 rename 新表名 :修改表名称
alter table 表名 change id s_id int(4),chenge:修改表属性,也可以删除自增长
alter table wuhan718 change s_id s_id int(4)auto_increment :修改字段名称并且给字段增加自增长
alrer table wuhan718 change s_id s_id int(4):删除字段名称也会删除自增长
alter table wuhan718 add age int(4):给表中添加一个字段 add:添加字段
alter table wuhan718 add(dcs1 int(1),dcs2 char(4):添加多个字段
alter table wuhan718 add sex char(4)not null :添加字段同时添加约束
alter table wuhan718 modify sex char(4)first:将sex字段挪到表第一个 modify:调整顺序;first:放到第一个
add 也可以结合first 和 after 使用
alter table wuhan718 add dcs17 char(4)first:新添加一个字段将它放在表格第一位
alter table wuhan718 drop dcs,drop dcs2: drop:删除字段;drop....,drop....:删除多个字段
删除主键约束必须先删除自增长
alter table wuhan718 drop primary key:删除主键约束
alter table wuhan718 change id id int(4)primary key auto_increment :增加主键约束,同时增加自增长
alter table:针对表的结构进行操作
create drop alter table 这几个都是输入表结构操作语法
|
|