1.连接数据:-u指用户名 -p指密码
mysql -uroot -p
输入密码
2.查看数据库中的文件
show databases
3.连接数据库文件
use 文件名
4.查看数据库中的所有表
show tables
5.新建表(primary key主键;not null非空;auto_increment自动增长)
create table 表名(字段1 类型 主键 primary key not null auto_increment,字段2 类型,.......)
创建表
方法1
create table 表名(字段1 字段1类型 primary key,字段2 字段2类型,........)
方法2
create table 表名(字段1 字段1类型 primary key not null auto_increment,字段2 字段2类型,........)
primary key设置该字段为逐渐,在一张表中只能有一个主键,主键数据必须唯一
auto_increment 自动增长
6.对表中数据进行增删改操作
添加
insert into 表名(字段1,字段2....)values(值1,值2.....)
修改:
update 表名 字段1=值1,字段2=值2
删除
delete from 表名 where 条件
查询
selet * from 表名 where 条件
7.对数据库中的数据结构进行增删改查操作
DESC 表名:查看表结构
修改表名称:alter table 原表名 rename 新表名
修改字段类型:alter table 表名 modify 字段名 字段类型
删除表:drop table 表名
修改字段名称:alter table 表名 change 原字段名 新字段名 新字段类型
添加字段:alter table 表名 add 新字段名 字段类型 约束条件
删除字段: alter table 表名 drop 字段名 (慎用)
将某个字段放在表中的第一个位置:alter table 表名 modify 字段1 字段类型 first
将某个字段放在表中的指定位置的后面:alter table 表名 modify 字段1 字段类型 after 字段2