启动数据库
mysql -uroot -p
password:密码
新建数据库
create database 库名;
删库
drop database 库名;
查看所有库
show databases;
进入库
use 库名;
新建表
create table 表名 (字段名1 类型 primary key auto_increment,字段名2 类型,字段名3 类 型);
查看所有表
show tables;
查看表结构
desc 表名;
查找
查找所有
select * from 表名;
查找一个
select * from 表名 where 字段值=参数;
分页查找
select * from 表名 limit 参数1,参数2;
添加
i nsert into 表名 value(字段值1,字段值2,字段值3);
修改
update 表名 set 字段1=值,字段2=值 where 条件字段=值;
删除
delete from 表名 where 条件字段=值;
创建从表
create table 从表名(主键字段 type1 primary key,字段2 type2,字段3 type2 references 主表名(主表主键字段));
多表联合查询
select u.name as uname,u.phone , o.price as oprice, o.addr, p.name as pname, p.price as pprice, d.count , t.name as tname
from users u
inner join orders o on o.uid = u.uid
inner join details d on o.oid = d.oid
inner join products p on d.pid = p.pid
inner join types t on p.tid = t.tid
where o.oid=‘c406647d62d411ea997c0d34dcb6fac2’
mysq语句
最新推荐文章于 2024-08-11 15:20:18 发布