查看当前数据库版本
select version();
创建数据库hehl
create database hehl default charset=utf8;
删除数据库
drop database hehl;
查看数据库
show database;
使用数据库:
use hehl;
查看当前数据库下的表
show tables;
创建数据表:
create table if not exists t_hehl1( // 如果不存在则创建
->id int unsigned auto_increment, // 自动加一
->password varchar(20) not null, // 不为空
->time timestamp, // 时间戳
->primary key(id)) // 主键
->engine=InnoDB default charset=utf8; // 存储引擎、编码
显示表结构:
show columns from t_hehl1;
删除数据表:
drop table test1;
向数据表中插入数据:
insert into t_hehl1(id, password, time) values (123, ‘test’, null);
insert into t_hehl1(id, password, time) values (null, 'test', null); // id属性自增
查看数据表中内容:
select * from t_hehl1;
查找数据表:
select * from t_hehl1 where id=123;
修改数据表:
update t_hehl1 set password='change' where id=123;
删除某一个数据表:
delete from t_hehl1 where id = 124;
按条件查找数据表:
select * from t_hehl1 where password like '%change';
将多个数据表中集合某项数据(如下图)
select password from t_hehl1
->union
->select password from t_hehl2
->order by password;