数据库:
查看所有数据库
show databases;
使用数据库
use 数据库名;
查看当前使用的数据库
select database();
创建数据库
create database 数据库名 charset=utf8;
例
create database liwen charset=utf8;
删除数据库
drop database 数据库名
drop database liwen;
数据表
查看当前数据库中所有的表
show tables;
查看表结构
desc 表名;
创建表
auto_increment表示自增长;
create table table_name(
column1 datatype contrai,
column2 datatype ,
column3 datatype,
。。。。。
columnN datatype,
primary key(one or more columns)
);
例:创建班级表
create table classs(
id int unsigned primary key auto_increment not null,
name varchar(20) default ‘张三’,/default为默认值,
age tinyint unsigned default 0,
height decimal(5,2),
gender enum('男’,‘女’,‘保密’),
cls_id int unsigned default 0
);
修改表-添加字段
alter table 表名 add 列名 类型;
例
alter table students add birthday datatime;
修改表-修改字段:重命名版
alter table 表名 change 原名 新名 类型及约束;
例
alter table students change birthday birth datatime not null;
修改表-修改字段:不重命名版
alter table 表名 modify 列名 类型及约束
例
alter table students modify birth data not null;
修改表-删除字段
alter table 表名 drop 列名;
例
alter table students drop birthday;
删除表
drop table 表名;
例
drop table students;查看表的创建语句
show create table 表名;
例
show create table students
mysql基本命令
最新推荐文章于 2025-04-16 23:47:36 发布