SQL学习 之 into outfile 和 into dumpfile

在学sqlmap的时候发现,写文件不用into outfile用的却是into dumpfile于是去查了一波。

the SELECT ... INTO form of SELECT enables a query result to be stored in variables or written to a file:

SELECT ... INTO var_list selects column values and stores them into variables.

SELECT ... INTO OUTFILE writes the selected rows to a file. Column and line terminators can be specified to produce a specific output format.

SELECT ... INTO DUMPFILE writes a single row to a file without any formatting.

原来select into有三种用法,还可以写入到变量中。。。

  • outfile可以写入多行数据,并且字段和行终止符都可以作为格式输出。
  • dumpfile只能写一行,并且输出中不存在任何格式。

注意,用这些函数先需要查看权限是否足够。

mysql> show variables like '%secure%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| secure_auth      | OFF   |
| secure_file_priv |       |
+------------------+-------+
2 rows in set (0.00 sec)

这个secure_file_priv应该为空,不然在读写文件时就会受到限制,甚至为NULL时无法读写,改的话很容易,在mysql的配置文件中加入一行secure_file_priv=然后重启mysql服务即可。

先来测试outfile

mysql> select * from test into outfile "c:/outfile.txt";
Query OK, 2 rows affected (0.00 sec)

在这里插入图片描述
再来测试dumpfile

mysql> select * from test into dumpfile "c:/dumpfile.txt";
Query OK, 2 rows affected (0.00 sec)

在这里插入图片描述
效果对比还是很明显的。

所以一般情况下,比如脱裤时,那就用outfile更好使,但是如果用outfife去导出二进制文件时,就会出错,因为outfile函数会在行末端写入新行,更致命的是会转义换行符,这样的话这个二进制可执行文件就会被破坏,所以一般导出导出二进制文件(udf提权)时就用dumpfile

发布了265 篇原创文章 · 获赞 266 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/u014029795/article/details/105222309