关于“库”
·查看所有数据库:show databases;
·使用库:use dvwa;(dvwa是库名)
·查看默认库:select database();
关于“表”
·查看所有表:show tables;
·查看表结构:desc 表名;
·查看创建表sql语句:show create table users(表名)\G(G:字段以行方式显示)
查看当前默认用户
·查看当前默认用户:select user();
查询语句
- 查询所有字段:select * from users;
- 查询指定字段:select user,password(要查询的字段user和password,多个字段要使用逗号来分开) from users;
- 条件查询(select字段from 表where 条件;):select 字段 from users where user=’admin’;(user=’admin’是要查询的数据)
- 逻辑与(select字段from 表where条件1 and条件2;):select 字段 from users where user=’admin’and user_id=6;(要比较的数据)
- 逻辑或(select字段from 表where条件1 or条件2;):select 字段 from users where user=’admin’or user_id=5;(要比较的数据)
联合union语句
作用:将两条sql语句联合起来查询
语法:sql1 union sql2
注意:两条sql语句查询字段(列)数必须相同,如果不相同,可以使用数字或空格代替列
实战:
猜测字段数:
#第一次猜测
Union select 1#
#第二次猜测
union select 1,2#
#结果:直到不报语法错误,就确认了结果是几个字段