文章目录
- 1. mysql数据库基础操作命令
- 1.1 数据库相关操作
- 1.远程连接数据库
- 2.查看mysql中有几个数据库
- 3.进入某个数据库
- 4.查看当前使用的数据库
- 5.创建新的数据库
- 6.删除数据库
- 1.2 表相关操作
- 1.创建表
- 2.删除表
- 3.修改表名
- 4.修改表结构(增添\删除\更改字段)
- 5.查看表的属性。
- 6.查看字段名与注释
- 1.3 数据相关操作
- 1.插入
- 2.更改
- 3.查询
- 3.1其他特殊用法
- 4.删除
- 2. 其他
- 3. 参考文章
1. mysql数据库基础操作命令
数据库名:testdb
表名:new123
1.1 数据库相关操作
1.远程连接数据库
mysql -h 192.168.124.8 -u root -p 123
2.查看mysql中有几个数据库
show databases;
3.进入某个数据库
use dvwa;
4.查看当前使用的数据库
select database();
5.创建新的数据库
create database test;
6.删除数据库
drop database test
1.2 表相关操作
1.创建表
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;
查看
2.删除表
drop table relationship;
3.修改表名
alter table relationship rename new123;
4.修改表结构(增添\删除\更改字段)
- 增加:
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;
#添加自动增长
只需要在更改的时候写上需要更改的属性,已经有的属性不需要写上。
更改前:
更改后:
5.查看表的属性。
desc new123;
6.查看字段名与注释
select column_name, column_comment from information_schema.columns where table_schema ='testdb' and table_name = 'new123' ;
1.3 数据相关操作
1.插入
#插入一条数据
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中。
2.更改
#将new123表中的name=tom的行中的sex属性改为man。
update new123 set sex='man' where name='tom';
3.查询
运算符:
算数运算符+ - * /
比较运算符>、=、<、!=、>=、<=
逻辑运算符: 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;
3.1其他特殊用法
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后面的数字就是代表的是根据第几个字段排序,如果数字所指的字段存在,则查询成功,不存在则查询失败。
4.删除
#清空表内数据
truncate new123;
delete from new123;
#删除指定条件的数据
delete from new123 where name='cat';
其他可参考mysql数据库命令这篇文章。
2. 其他
当删除了某一个数据的时候,主键例如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中的注释符号有三种,第二个–后面必须加上空格
#…
– …
/…/
mysql修改字段的排列位置
给MySQL表增加指定位置的列
3. 参考文章
Bypass disabled_functions一些思路总结
Web-Security-Learning
mysql数据库命令
mysql注入可报错时爆表名、字段名、库名
详解SQL盲注测试高级技巧
MySQL False注入及技巧总结
Mysql注入攻击与防御
sql注入总结
XSS总结
浅析Redis中SSRF的利用
Bypass一些命令注入限制的姿势
更多推荐
web安全学习-sql注入-mysql基础
发布评论