MySQL的基本目录

MySQL常用dos命令

 登陆MySQL

 MySQL常用dos命令

 

查看数据库

Show databases;

 MySQL常用dos命令

 

创建数据库

Create database 数据库的名字;

 MySQL常用dos命令

 标准创建语句:

Create database if not exists 数据库的名字

 MySQL常用dos命令

 

删除数据库

语句:

Drop database if exists 数据库的名字

 MySQL常用dos命令

 

 修改数据库的名字

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

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

 
修改字符集

 MySQL常用dos命令

 

 创建表

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

 MySQL常用dos命令

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

 MySQL常用dos命令

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

创建表的语法:

Create table [if not exists] 表名(

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

……

)engine=myisam default charset=utf8;

 MySQL常用dos命令

 

查看表结构

语句: desc 表名;

 MySQL常用dos命令

 

查看创建语句

语句: show create table 表名;

 MySQL常用dos命令

 

添加字段

1.默认添加

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

默认添加到最后

 MySQL常用dos命令

2.添加到什么字段之后

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

 MySQL常用dos命令

3.添加到第一位

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

 MySQL常用dos命令

综合起来:

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

 

删除字段

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

 MySQL常用dos命令

 

 修改数据类型

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

 

 MySQL常用dos命令

 

修改字段名

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

 MySQL常用dos命令

 

修改表名

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

 MySQL常用dos命令

 

删除表

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

 MySQL常用dos命令

转自https://www.cnblogs.com/pandaQQQ/p/9628582.html

相关文章:

  • 2022-01-13
  • 2021-10-23
  • 2022-01-12
猜你喜欢
  • 2021-11-14
  • 2021-10-31
  • 2021-07-24
  • 2021-09-09
相关资源
相似解决方案