不言不语

您现在的位置是: 首页 >  数据库  >  MYSQL

MYSQL

MySQL基本操作命令

2022-06-03MYSQL
MySQL基本操作命令

1.查看当前有哪些数据库?

   show databases;

 

2.如何创建一个数据库?

   create database s01;

 

3.删除数据库

   drop database s01;

 

4.进入一个数据库

   use s01;

 

5.如果查看当前在哪个数据库中?

   select database();

 

6.查看当前数据库有哪些表

   show tables;

 

7.创建表

   create table stu(

      id int auto_increment primary key,

      name varchar(50) unique not null,

      sex tinyint not null default 0,

      email varchar(255) not null default ''

   )engine=MyISAM default charset=utf8;

 

8.删除表

   drop table stu;

 

9.如果查看建表语句(已经创建好的表,想知道是怎么创建的)

   show create table 表名\G

 

10.如何查看表结构

   desc 表名;

 

11.添加列

   alter table 表名 add 列名 类型 约束;   (add 后面的部份,与建表语句一样)

 

12.删除列

   alter table 表名 drop 列名;

 

13.修改列信息

   alter table 表名 change 原列名 新列名 类型 约束  (后面部份与建表语句一样)

 

14.设整列顺序

   alter table 表名 change 原列名 新列名 类型  约束 after 列名;

 

15.如何改表名称

   alter table 表名 rename as 新表名;

 

16.如何改表引擎

   alter table 表名 engine 新的引擎;

文章评论