查看當前數據庫版本
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;