-
net start mysql80 启动数据库服务器
-
net stop mysql 停止数据库服务器
-
mysql -uroot -p 登录数据库服务器
-
create database 数据库名; 创建数据库
-
use 数据库名; 进入数据库
-
show databases; 显示所有数据库
-
show tables; 显示所有表
-
create table 表名(属性字段 数据类型); 创建表
-
describe 表名;(desc 表名) 查看表结构
-
insert into 表名 values('属性值'); 向表中添加数据
-
delete from 表名 where 属性字段=属性值; 删除表中的数据
-
update 表名 set 属性字段=属性值 where 属性字段=属性值; 修改表中的数据
-
select 数据字段 from 表名; 查找表中的数据
-
create table 表名(属性字段 数据类型 primary key); 设置主键约束
-
create table 表名(字段1 类型, 字段2 类型, primary key(字段1,字段2)); 设置联合主键约束
-
create table 表名(属性字段 数据类型 primary key auto_increment); 自增约束
-
alter table 表名 add primary key(属性字段) 设置主键约束
-
alter table 表名 drop primary key(属性字段) 删除主键约束
-
alter table 表名 add unique(属性字段) 设置唯一约束
-
alter table 表名 drop index 属性字段 删除唯一约束
-
create table 表名(属性字段 数据类型 not null); 设置非空约束
-
create table 表名(属性字段 数据类型 default xxx); 设置默认约束
-
create table 表名(属性字段 数据类型 foreign key(主表的数据字段) references 副表表名(副表主键的数据字段)); 设置外键约束
-
alter table 表格名 add column 数值 类型; 向某一个表格中添加一列
-
select max(数据字段) from 表名; 最大值
-
select min(数据字段) from 表名; 最小值
-
select distinct 数据字段 from 表名; distinct 排重
-
select 数据字段 from 表名 where 数据字段 in(属性值,属性值); in 或
-
select 数据字段 from 表名 where order by desc; desc 降序
-
select 数据字段 from 表名 where order by asc; asc 升序 默认为升序
-
select 数据字段 from 表名 limit 索引index,条数n; limit 获取表中index开始的n条数据 index起始值为0
-
select avg(数据字段) from 表名; avg 平均值
-
select 数据字段 from 表名 group by; group by 分组
-
select * from 表名 where 数据字段 like '3%'; like 模糊查询 % 任意
-
select yarn(数据字段) from 表名; yarn 取年份
-
select yarn(now()) from 表名; yarn(now()) 取当前年份
-
select 数据字段 from 表名 where 数据字段 not in(属性值,属性值); not 取反
-
select 数据字段 from 表名 union select 数据字段 from 表名; union 并集
-
select 数据字段 from 表名 where 数据字段 > any(select 数据字段 from 表名); any 至少
-
select 数据字段 from 表名 where 数据字段 > all(select 数据字段 from 表名); all 所有
-
select count(数据字段) from 表名; count 统计
-
select 数据字段 from 表1 join 表2 where 表1.数据字段 = 表2.数据字段; join on 内连接 两个表的交集
-
select 数据字段 from 表1 left join 表2 where 表1.数据字段 = 表2.数据字段; left join on 左连接 合并两个表,表2中没有的数据默认为null
-
select 数据字段 from 表1 right join 表2 where 表1.数据字段 = 表2.数据字段; right join on 右连接 合并两个表,表1中没有的数据默认为null
-
select 数据字段 from 表1 full join 表2 where 表1.数据字段 = 表2.数据字段; full join on 全连接 合并两个表 不推荐使用
-
set autocommit = 0; 设置事务的状态
-
commit; 事务提交
-
rollback; 事务回滚
-
begin;(start transaction) 开启局部手动提交事务
-
select @@global.transaction_isolation; 查看系统级别的事务隔离性
-
select @@transaction_isolation; 查看回话级别的事务隔离性
-
set global transaction isolation level read uncommitted; 设置隔离级别
-
select @@autocommit; 查询事务的状态