show databases;
show tables;
create database baseName;
create table tableName (字段 类型 约束[,字段 类型 约束]);
show create database baseName;
show create table tableName;
use baseName;
desc tableName;
drop database baseName
drop table tableName;
alter table tableName add age datetime;
alter table tableName modify age date; 修改
alter table tableName change age aged date default ‘1990’;
alter table tableName drop age;
auto_increment 表示自动增长
not null 表示不能为空
primary key 表示主键
default 默认值
unsigend 无符号的类型
enum(“a”,“b”,“c”)
1.链接数据库
mysql -u root -p
mysql -u root -p pwd
2.退出数据库
exit/quit/ctrl + d
3.查看所有数据库
show databases;
4.显示时间
select now();
5.显示数据库版本
select version();
6.创建数据库
create database baseName;
create database baseName charset = utf8;
7.查看创建数据库的语句
show create database baseName;
默认方式创建的数据库编码格式是拉丁文
8.删除数据库
drop database
baseName
这里需要说明一下,如果baseName的名字出现特殊字符,需要将名字作为一个整体,在名字外面加上` 这个点是键盘esc下面的那个点。
9.查看当前使用的数据库
select database();
10.进入数据库
use baseName;
》》》》》》》》》》》》》》》》》》》》》》》》》》表
11.查看当前数据库的所有表
show tables;
12.创建数据表
create table tableName (字段 类型 约束[,字段 类型 约束]);
create table tableName(id int primary kye not null auto_increment,name varchar(20));auto_increment 表示自动增长
not null 表示不能为空
primary key 表示主键
default 默认值
unsigend 无符号的类型
enum(“a”,“b”,“c”)
13.进入表
desc tableName;
14.查看表的创建语句
show create table tableName;
》》》》》》》》》》》》》》》》》》》》》表的修改
- 添加字段
alter table tableName add age datetime;
16.修改表(不改字段名)
alter table tableName modify age date;
17.修改表(改字段名)
alter table tableName change age aged date default ‘1990’;
18.删除表字段
alter table tableName drop age;
19.删除表
drop table tableName;