打开数据库:show dateabases;
创建数据库:create dateabases;
使用数据库:use 数据库名;
删除数据库:drop dateabases 库名;
查看所有表:show tables;
向表里添加数据:insert into 表名(字段名1,…)values(值1,…);
查询表中所有数据:select * from 表名;
带条件查询:select * from 表名 where 条件(字段名=值);
更改字段数据:update 表名 set 字段名=要更改的数据 where 条件;
带范围查询:select * from 表名 where 字段名 between 值1 and 值2;(1-50,包括1)
带like字符匹配查询:select * from 表名 where 字段名 like ‘要匹配的数据’;(粗糙匹配)
select * from 表名 where 字段名 like ‘_值’/‘值%’;(带%_查询,_是开头相似/%是结尾相似)
查询空值:select * from 表名 where 字段名 is null;
查询非空:select* from 表名 where 字段名 is not null;
使用and实现多条件查询:select * from 表名 where 字段名 条件1 and 条件2;(条件要同时满足)
使用or实现多条件查询:select * from 表名 where 字段名 条件1 or 条件2;(一条满足)
筛选重复的记录:select distinct 字段名 from 表名;
清除表数据:delete from 表名 where 条件;(带条件查询)
=、delete from 表名;(全删)
更改表名:alter table 旧表名 rename to 新表名;
更改字段数据类型:alter table 表名 modify 字段名 新数据类型;
更改字段名以及数据类型:alter table 旧表名 新表名 新数据类型;
添加字段:alter table 表名 add 字段名 数据类型[约束条件(可选)] after/first (可选) 已有字段;
删除字段:alter table 表名 drop 字段名;
更改数据库引擎:alter table 表名 engine 要更改的引擎名;
MySQL操作语句
最新推荐文章于 2023-08-08 21:59:23 发布