一、基础常用命令
1.创建命令
create user ‘用户名’ @‘ip’ identified by ‘密码’; 创建用户
drop user 用户名@ip 删除用户
show databases; 查数据库
show tables; 看表
create database 数据库名 default charset utf8; 创建数据库
create table 表名(列名 数据类型 约束···,列名 数据类型 约束···)engine=innodb default charset=utf8 创建表
其中数据类型种类 数字(int,tinyint,smallint,float,double),字符串(char(个数)varchar(个数))时间(DATE,TIME,DATETIME),枚举enum(值只能是枚举中的元素),集合set(值只能是结合元素的组合)
2.查表命令
条件查询
select * from 表名;
select 列名···from 表名;
select 列名 from 表名 where 列名(id等) >/</!= value;
select 列名,常量 from 表名; 增加一个常量列
select 列名 from 表名 where 列名 in/not in/between and value;
select 列名 from 表名 where 条件1 and 条件2;
特殊的:select 列名 from 表名 where 列名 in (select 列名(只能一列) from 表名);
select 列名 from 表名 where 列名 like ‘xx%’/’%xx’/“xx_”; 查询以xx开头/xx结尾 ,%代表任意位,_代表一位
select xx,(select xx from …) from … 查询条件做常量值<