在DOS命令界面进入数据库:mysql -uroot -p
一、操作数据库
- 查看数据库
show databases;
- 创建数据库
create database 数据库名;
- 查看数据库
show create database 数据库名;
- 删除数据库
drop database 数据库名
- 使用数据库
use 数据库名;
二、操作数据表
注意:如果没有使用数据库,就不能对数据库里面的表进行操作了。
- 查看数据库下的数据表
show tables;
- 创建数据表
create table 表名(字段名1 值1字段名2 值2.....
);
- 查看表详情
show create table 表名;
- 创建指定引擎和字符集
create table 表名(字段名1 值1字段名2 值2....
)engine=myisam/innodb charset =utf8/gbk;
- 查看表字段
desc 表名;
- 修改表名
rename table 原表名 to 新表名;
- 添加表字段
alter table 表名 add 字段名 字段数据类型; //默认在最后alter table 表名 add 字段名 字段数据类型 first; //最前面alter table 表名 add 字段名 字段数据类型 after 字段名xx; //在字段名xx后面
- 删除表字段
Alter table 表名 drop 字段名;
- 修改表的字段名和类型
Alter table 表名 change 原字段名 新字段名 类型;
- 修改字段类型和位置
Alter table 表名 modify 字段名 新类型 first; //最前Alter table 表名 modify 字段名 新类型 after 字段名xx; //字段名xx之后
- 删除表
drop table 数据表;
公众号:java学习大本营