数据库名:testdb 表名:new123
mysql -h 127.0.0.1 -u root -p 123
show databases;
use dvwa;
select database();
create database test;
drop database test
primary key --主键 not null --不为空 default --默认值 auto_increment----自增
create table relationship (id int(4) primary key,name char(10)
not null,sex char(2));
创建完成后可以用show tables;
查看
drop table relationship;
alter table relationship rename new123;
alter table new123 add address char(10) not null;
增加address字段alter table new123 drop address;
#删除address字段alter table new123 change age age int(4) not null;
#更改age字段的属性
alter table new123 change id id int(4) auto_increment not null;
#添加自动增长只需要在更改的时候写上需要更改的属性,已经有的属性不需要写上。
更改前:
更改后:
desc new123;
select column_name, column_comment from information_schema.columns where table_schema ='testdb' and table_name = 'new123' ;
#插入一条数据
insert into new123 (name,sex,address,age) values('tom','man','beijing',20);
insert into new123 (name,sex,address,age) values('lucy','woman','shanghai',19);
#插入多条数据
insert into new123 (name,sex,address,age) values ('cat','woman','hebei',24),('cody','man','sichuan',22);
有auto_increment属性的字段不需要写在insert中。
#将new123表中的name=tom的行中的sex属性改为man。update new123 set sex='man' where name='tom';
运算符:算数运算符+ - * / 比较运算符>、=、<、!=、>=、<= 逻辑运算符: and or not
报错查询确定字段数,表有几个字段,union select 后面就要有几个数字,当数字的数量与字段数一致的时候,此次查询就不会报错,否则就会报错,如new123表有5个字段,因此我在sql语句中跟了1-5,共五个数字,这时候查询成功了没有报错。
select * from new123 where id = 1 and false union select 1,2,3,4,5;
limit
select*from new123 limit 0,2;
上述sql命令的意思是,查询new123表的所有数据,从第0行开始显示,一共显示2行。
like
select*from new123 where age like '2%';
上述语句的意思是查询new123表的所有数据,并输出所有年龄中含有2的值。一个百分号可以代表不限数量的任意字符。
count
select count(*) from new123;
上述语句的意思是,查询new123表内的所有数据,并显示查询出的数据条数。
Sum
select*from new123 where age = 22 and false union select (select sum(age) from new123),null,null,null,null;
求new123表中age的这一个字段所有值的和。
max/min
select*from new123 where age = 22 and false union select (select max(age) from new123),null,null,null,null;
求new123表中age的这一个字段最大值,将max改为min就为求最小值。
avg
select*from new123 where age = 22 and false union select (select avg(age) from new123),null,null,null,null;
求平均值
distinct
select distinct sex from new123;
去重复 order by(升序排序)/ Order by....desc(降序排序)`
select*from new123 where age = 22 and false union select * from new123 order by 5;
可以通过order by 确认字段数,order by后面的数字就是代表的是根据第几个字段排序,如果数字所指的字段存在,则查询成功,不存在则查询失败。
清空表内数据
truncate new123;
delete from new123;
删除指定条件的数据
delete from new123 where name='cat';
其他可参考mysql数据库命令这篇文章。
当删除了某一个数据的时候,主键例如id变得不连续了,这里提供一个解决方案:
添加一个字段并将字段挪到指定字段的后面或者放到第一个,语法如下:
ALTER TABLE table_name ADD [COLUMN] col_name column_definition [ FIRST | AFTER col_name]
alter table new123 drop id;
alter table new123 add id int(4) primary key auto_increment first;
desc new123;
alter table new123 modify id int(4) primary key auto_increment first;
MySQL中的注释符号有三种,第二个–后面必须加上空格
#… – … /…/
[0]参考文章:https://blog.csdn.net/qq_41874930/article/details/112259822
[19]mysql数据库命令:https://www.jianshu.com/p/8c7261bfaa94
[20]mysql修改字段的排列位置:https://blog.csdn.net/nangeali/article/details/73015099
[21]给MySQL表增加指定位置的列:https://blog.csdn.net/seven_3306/article/details/39051493
[22]Bypass disabled_functions一些思路总结:https://xz.aliyun.com/t/4623
[23]Web-Security-Learning:https://chybeta.github.io/2017/08/19/Web-Security-Learning/
[24]mysql数据库命令:https://www.jianshu.com/p/8c7261bfaa94
[25]mysql注入可报错时爆表名、字段名、库名:http://www.wupco.cn/?p=4117
[26]详解SQL盲注测试高级技巧:https://www.freebuf.com/articles/web/30841.html
[27]MySQL False注入及技巧总结:https://www.anquanke.com/post/id/86021
[28]Mysql注入攻击与防御:https://www.anquanke.com/post/id/85936
[29]sql注入总结:https://www.cnblogs.com/JetpropelledSnake/p/9017218.html