1.数据库操作
create database 数据库名; create database if not exists 数据库名; -- 如果不存在则创建 show databases; --展示所有数据库 show create database 数据库名; --展示创建数据库脚本 drop database 数据库名称; --删除数据库 use 数据库名; --切换数据库
2.数据表操作
show tables;-- 展示所有表
desc 表名; --显示表结构
show create table 表名; --查看建表语句
drop table 表名; --删除表
create table 表名(
id int primary key,
字段名 类型(长度) 约束,
字段名 类型(长度) 约束
);--创建数据表
alter TABLE 表名 CHARACTER SET 字符集 --修改表字符集
3.字段操作
alter table 表名 drop primary key; --删除字段 alter TABLE 表名 DROP 列名; --删除字段 alter TABLE 表名 CHANGE 列名 新列名 列类型; --修改表名 alter table 表名 add 列名 列类型; --新增列
4.索引操作
alter table 表名 add index 索引名 (字段名1[,字段名2 …]); --加索引 alter table 表名 add primary key (字段名);--加关键字索引 alter table 表名 add unique 索引名 (字段名); --加唯一索引 alter table 表名 drop index 索引名; --删除索引