创建表 删除表 更改表名 查看表结构 查看创建的数据库属性 在表中插入数据 修改数据库编码方式
Mysql操作
mysql -uroot -p密码
create database 数据库库名;
drop database [if exists] 数据库库名;
show databases;
use 数据库库名;
show tables;
show variables like 'storage engine%';
表的操作
create table 表名 ( 字段名 数据类型(长度) [属性] ); # 案例 create table 表名( name varchar(20) not null );
drop table 表名;
alter table 旧表名 rename 新表名;
desc 表名;
show create database 数据库库名;
insert into 表名 value (数据1,数据2,...);
insert into 表名 (字段名1,字段名2,...) value (数据1,数据2,...);
alter database 数据库库名 default character set utf8 collate utf8_bin;
表中数据的查询
select * from 表名;
select 列名 from 表名;
select * from 表名 where 列名 = x;
select * from 表名 where 列名 in(xx,xx,...);
select * from 表名 where 列名 between xx and xx;
select distinct 列名 from 表名;
select * from 表名 where 列名 like '%xx';
select * from 表名 where 列名1 = xx and/or 列名2 = xx;
select 列名 别名 from 表名;
select 列名 as 别名 from 表名;
select count(列名) from 表名;
select count(distinct 列名) from 表名;
select sum(列名) from 表名;
select * from 表名 order by 列名 ASC;
select * from 表名 group by 列名
select count(*) from 表名 group by 列名;
Having sum(...)<1300;
select group_count(字段名) from 表名 group by 字段名;
select * from 表名 with rollup;
limit 偏移量(开始下标),待取记录数;
select * from 表名 limit 0,10;
多表查询
select * from 表1 cross join 表2;
select 查询字段 from 表1 [inner] join 表2 on 表1.关键字段 = 表2.关键字段;
select 所查字段 from 表1 [left/right/outer] join 表2 on 表1.关系字段 = 表2.关系字段 where 条件;
表中记录更新
update 表名 set 列名1 = 新值, 列名2 = 新值;
update 表名 set 列名 = 新值 where 某列名 = x;
表中记录删除
delete from 表名 where 字段名 = 要删除行的字段值;
表字段操作
alter table 表名 change 旧字段名 新字段名 新数据类型;
alter table 表名 modify 字段名 新数据类型;
alter talbe 表名 add 字段名 数据类型;
alter table 表名 add 新字段名 新数据类型 [约束条件] first/(+after 旧字段名);
alter table 表名 modify 字段名1 数据类型 first/(after 字段2);
表的约束
alter table 表名 modify 列名 数据类型 null;
alter table 表名 modify 列名 数据类型;
alter table 表名 modify 列名 数据类型 not null;
alter table 表名 drop primary key;
alter table 表名 alter 列名 drop default;
alter table 表名 drop key 约束名;
constraint fk_id foreign key (本表字段) references 引用表(引用的列);
alter table 表名 drop foreign key 外键名;
alter table 表名 drop key fk_id;
alter table 表名 add constraint fk_id foreign key (本表字段) references 引用表(引用的列);
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算