数据库基础
创建数据库
create 数据库名称;
创建表
create table if not exists mobile(
ID int(10) primary key auto_increment comment '手机编号 主键自增',
Brand varchar(50) not null comment '手机品牌 非空约束',
Model varchar(50) not null comment '手机型号 非空约束',
Price int(10) not null comment '手机价格 检查约束',
Count int(10) not null comment '手机库存 检查约束',
Version varchar(50) not null comment '手机版本号 非空约束'
);
添加数据
insert into mobile values(default,"Apple","IPHone4s",4999,100,"chain");
insert into mobile values(default,"huawei","Z3L55",3999,100,"chain");
insert into mobile values(default,"Mi","小米13",2999,100,"chain");
删除数据
delete from mobile where id = 1;
修改数据
update mobile set price = 1999 ,count = 200 where id = 2;
查询数据
select * from mobile;
select * from mobile where id =2;
select id,brand from mobile;
常用操作
select user(); # 查询当前用户
select version(); # 查询版本
select @@datadir; # 查询安装mysql路径
select @@version_compile_os; # 查询os系统
select database(); # 查询当前数据库
涉及函数
CONCAT(s1,s2...sn)函数
作用:将多个字符串连接成一个字符串
select concat(id,"-",brand) from mobile;
CONCAT_WS(x, s1,s2...sn)函数
作用,与concat()函数一样,唯一的不同点是:可以一次性指定分隔符
select concat_ws("-",id,brand,version) from mobile;
left(s,n)函数
作用:返回字符串s的前n个字符
语法:left(str,length)
str:需要截取的字符串
length:截取多少位。注入过程中一般是1位
用法:left("autumn",1) # 返回
select left("autumn",1);
substr()函数
作用:截取字符串
语法:substr(str,start,length)
str:需要截取的字符串
start:起始位置
length:为长度,一般位1
用法:substr((select database()),1,1)
select substr((select database()),1,1);
length()函数
作用:获取字符串的长度
语法:length(str)
用法:length(database())
limit函数
作用:输出的条目
语法:limit num start,num length
用法:limit 0,1
if()条件语句
作用:分支选择语句
语法:if(条件表达式,true,false)
用法:if(length(database())>1,sleep(5),0)
sleep()函数
作用:休眠
语法:sleep(num)
用法:sleep(5)
extractvalue(XML_document, XPath_string);
第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc
第二个参数:XPath_string (Xpath格式的字符串).
作用:从目标XML中返回包含所查询值的字符串
用法:and extractvalue(null,concat(0x7e,(select version()),0x7e)) from demo;
UPDATEXML (XML_document, XPath_string, new_value);
第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc
第二个参数:XPath_string (Xpath格式的字符串)
第三个参数:new_value,String格式,替换查找到的符合条件的数据
作用:改变文档中符合条件的节点的值
用法:and updatexml(null,concat(0x7e,(select version()),0x7e),null);
php 函数
mysqli_multi_query()函数
作用:函数执行一个或多个针对数据库的查询。多个查询用分号进行分隔。
语法:mysqli_multi_query(connection,query);
connection 必需。规定要使用的 MySQL 连接。
query 必需。规定一个或多个查询,用分号进行分隔。
用法:
mysql_multi_quer()函数 与 mysqli_multi_query一致
information_schema库讲解
在MySQL数据库中5.0以上的版本中,存放着一个叫information_schema库,5.0以下的版本中没有information_schema库。
information_schema里面有很多表,其中重点是下列三个表:
columns:information_schema.clumns表,table_schema中存放着所有库名,**table_name **中存放着所有表名,column_name存放着所有列名
tables:information_schema.tables表,table_schema中存放着所有库名,table_name中存放着所有表名
schemata:information_schema.schemata表的schema_name列存放着所有数据库的库名
26万+

被折叠的 条评论
为什么被折叠?



