>  기사  >  데이터 베이스  >  SQL xp_cmdshell

SQL xp_cmdshell

大家讲道理
大家讲道理원래의
2016-11-10 11:15:10966검색

GO
---打开xp_cmdshell
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE
 
GO
---创建文件夹
declare @shellCommand nvarchar(1024)
Set @shellCommand='"mkdir C:\sqlcreatefold"'
exec xp_cmdshell @shellCommand
 
GO
--复制文件--准备一个空的文本文件在C盘
declare @shellCommand nvarchar(1024)
Set @shellCommand='Copy "C:\1.txt'+'" "C:\sqlcreatefold\1.txt'+'"'
exec xp_cmdshell @shellCommand
GO
--导出数据到TXT
Create table ##temp(line varchar(100))
Insert into ##temp(line)values('asdfghjklasdfghjkl')
Insert into ##temp(line)values('一二三四五六七')
declare @shellCommand nvarchar(1024)
Set @shellCommand='bcp "Select line From ##temp" queryout C:\sqlcreatefold\1.txt'+' -S"." -U"sa" -P"123456" -c -T'
exec xp_cmdshell @shellCommand
drop table ##temp
 
GO
--读取TXT文件
Create table ##temp(line varchar(100))
exec(N'bulk insert ##temp from N''C:\sqlcreatefold\1.txt''')
select * From ##temp
drop table ##temp
 
GO
--调用RAR--压缩文件夹
declare @shellCommand nvarchar(1024)
declare @WinRar varchar(128)
set @WinRar='C:\Program Files\WinRAR\WinRAR.exe'
Set @shellCommand='""'+@WinRar+'"  a -ep1 -afzip -df -ibck C:\sqlcreatefold\Package.zip C:\sqlcreatefold"'
exec xp_cmdshell @shellCommand
set @shellCommand='" dir C:\sqlcreatefold"'
exec xp_cmdshell @shellCommand

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.