1.创建一个表
drop table if exists test; //创建表之前,先判断删除库中已存在的的表。
create table test(
id int(11) not null auto_increment,
name varchar(40) not null,
password varchar(255) not null,
primary key (id)
)engine=InnoDB auto_increment=2 default charset=utf8;
注:auto_increment 主键自增从1开始,default charset=utf8设置数据库默认编码,engine=InnoDB 为存储引擎,InnoDB,是MySQL的数据库引擎之一,InnoDB支持事务处理和外键等高级功能。
2.插入新纪录
2.1 单条插入
insert into test(id,name,password) values (1,'张三','123-1')
等同于
insert into test(name,password) values ('张三','123-1')
2.2批量插入
insert into test (name,password) values
('李四','123-2'),
('王五','123-3'),
('赵六','123-4');
3.修改记录
update test set password='456' WHERE id='1';
4.查询
select * from test;
select * from test where id>2;
5.删除
5.1删除表数据,保留表结构
delete from test where id=2;
delete from test
5.2删除表结构即整个表在库里消失
drop table test;