MySQL基本语句、存储引擎
数据库服务器中存放的是 库(文件加) 表(文件) 表里面是记录(一行数据)
quit or exit 退出客户端
\s \c \G
quit or exit 退出客户端
\s \c \G
库(文件)
创建
create database 数据库名 charset 编码名称
修改
alter database 数据库名 charset gbk
查
show databases; 查看所有数据
show create database 数据库名 查看建库语句
删除
drop database 数据库名
表(字段)
创建
create table t1(id int,name char);
修改
改结构
alter table 表名 add | drop | modify | change
add 后面跟 字段名 数据类型
drop 后面跟 字段名
modify 后面跟 字段名 新类型
change 后面跟 旧字段名 新的字段名 新类型
该属性
编码
alter table t1 charset gbk;
表名
rename table 旧表名 to 新表名
查
show tables;
show create table 表名 查看建表语句
desc 表名 查看表结构(字段)
删除
drop table 表名
truncate table 表名,重建表(清空数据)
记录(数据内容)
添加
insert into 表名 values(值1...),(值1....)....
插入时注意 值得顺序 和 类型必须与表结构一致
修改
update 表名 set 字段名=新的值 where 条件
可以同时修改多行 用逗号来隔开字段
没有条件就全改
查
select *|字段名 from 表名 *表示所有字段
删除
delete from 表名 where条件
没有条件就全删
创建
create table t1(id int,name char);
修改
改结构
alter table 表名 add | drop | modify | change
add 后面跟 字段名 数据类型
drop 后面跟 字段名
modify 后面跟 字段名 新类型
change 后面跟 旧字段名 新的字段名 新类型
该属性
编码
alter table t1 charset gbk;
表名
rename table 旧表名 to 新表名
查
show tables;
show create table 表名 查看建表语句
desc 表名 查看表结构(字段)
删除
drop table 表名
truncate table 表名,重建表(清空数据)
记录(数据内容)
添加
insert into 表名 values(值1...),(值1....)....
插入时注意 值得顺序 和 类型必须与表结构一致
修改
update 表名 set 字段名=新的值 where 条件
可以同时修改多行 用逗号来隔开字段
没有条件就全改
查
select *|字段名 from 表名 *表示所有字段
删除
delete from 表名 where条件
没有条件就全删
存储引擎
存储引擎说白了就是如何存储数据、如何为存储的数据建立索引和如何更新、查询数据等技术的实现方法。因为在关系数据库中数据的存储是以表的形式存储的,所以存储引擎也可以称为表类型(即存储和操作此表的类型)。在Oracle 和SQL Server等数据库中只有一种存储引擎,所有数据存储管理机制都是一样的。而MySql数据库提供了多种存储引擎。用户可以根据不同的需求为数据表选择不同的存储引擎,用户也可以根据自己的需要编写自己的存储引擎。
show engines;
create table t0(id int not null)=csv t0.csm t0.frm t0.csv
create table t0(id int not null)=csv t0.csm t0.frm t0.csv
create table t1(id int)engine=innodb; 结构 数据 t1.frm (frame) t1.ibd (innodb data);
create table t2(id int)engine=myisam;结构 数据 索引 t2.MYD (myisam data) t2.MYI (myisam index) t2.frm (frame);
create table t3(id int)engine=blackhole;结构 t3.frm
create table t4(id int)engine=memory;结构 数据存内存-断电消失 t4.frm
create table t2(id int)engine=myisam;结构 数据 索引 t2.MYD (myisam data) t2.MYI (myisam index) t2.frm (frame);
create table t3(id int)engine=blackhole;结构 t3.frm
create table t4(id int)engine=memory;结构 数据存内存-断电消失 t4.frm