1:流程命令
- cmd命令打开数据库---mysql -u root -p
- show databases; ---查看所有数据库cre
- use <数据库名>---打开数据库
- create database <数据库名> charset=编码格式 --- 创建数据库;
- drop databases <数据库名>---删除数据库
- use<数据库名>--选中数据库
- show tables---查看数据库中的表
- desc <表名>---查看表的结构
- select * from <表名>---查看表中数据 星号*指代所有列的快捷方式
- drop tables <表名> --删除表
- rename database <旧> to <新>---修改数据库的名字
- rename table <旧> to <新>---修改表的名字
2.编辑表内数据命令
(1)给表加/修改/删除字段
在表的最后追加字段:
alter table 表名 add 字段名 数据类型;
在表的前面添加字段:
Alter table 表名 add 字段名 数据类型 first;
在表的指定字段后面添加字段:
Alter table 表名 add 字段名 数据类型 after 指定字段
修改字段名字:
Alter table 表名 change 旧字段 新字段 新字段数据类型
修改字段的数据类型
Alter table 表名 modify 字段名 新的字段类型
修改字段位置(到某个字段后面):
Alter table 表名 modify 字段名 int after 想移的字段名字
删除字段:
Alter table 表名 drop 字段名
给某个字段添加主键
alter table 表名 add constraint 自定义主键名 primary key `表名`(`添加主键的字段`);
(2)往表内插入数据:
往最后一行插入:
insert into <表名> (<字段名1>,<字段名2>,…)
Values(数据1,数据2,…),
(数据1,数据2,…);
(3)查询表中数据:
Select * from <表名> where 查询条件
查询表中列的数据 select 列名 from 表名
(4)修改表中数据
修改一个数据:
update <表名> set <字段名>=新数据 where 查询条件
修改一行数据:
update <表名> set 列名1=新数据1,列名2=新数据2, where 查询条件
修改同一字段为同一个值:
Update <表名> set <字段名>=<新数据> where <查询条件> in ( 值 )
(5)删除表中数据
删除一行数据:
Delete from <表名> where 查询条件