pandaQQQ

MySQL的基本目录

 登陆MySQL

 

 

查看数据库

Show databases;

 

 

创建数据库

Create database 数据库的名字;

 

 标准创建语句:

Create database if not exists 数据库的名字

 

 

删除数据库

语句:

Drop database if exists 数据库的名字

 

 

 修改数据库的名字

如果数据库没有数据,那就直接删除,从新创建

如果有数据,那就先备份,再删除,再创建,再导入数据

 
修改字符集

 

 

 创建表

创建表之前必须进入对应的数据库:use 数据库的名字

 

 首先需要查看该数据库下面的表:show tables;

 

数据库里面的表名不能重复!

创建表的语法:

Create table [if not exists] 表名(

字段名 数据类型 约束 其余…,

……

)engine=myisam default charset=utf8;

 

 

查看表结构

语句: desc 表名;

 

 

查看创建语句

语句: show create table 表名;

 

 

添加字段

1.默认添加

语句:alter table 表名 add 字段名 数据类型 约束

默认添加到最后

 

2.添加到什么字段之后

语句: alter table 表名 add 字段名 数据类型 约束 after 字段名;

 

3.添加到第一位

语句: alter table 表名 add 字段名 数据类型 约束 first;

 

综合起来:

Alter table 表名 add 字段名 数据类型 约束 [after 字段名/first]

 

删除字段

语句: alter table 表名 drop 字段名;

 

 

 修改数据类型

语句: alter table 表名 modify 字段名 数据类型 约束;

 

 

 

修改字段名

语句: alter table 表名 change 老的字段名 新的字段名 数据类型 约束

 

 

修改表名

语句: alter table 老的表名 rename 新的表名;

 

 

删除表

语句: drop table [if exists] 表名;

 

 

相关文章: