• SQL Server 阻止了对组件“xp_cmdshell”的 过程“sys.xp_cmdshell”的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。


    今天在创建数据库的时候突然发现,xp_cmdshell的存储过程不能用了,网上一搜,发现大部分都是只关闭安全配置,然后就有了下文

    代码:具体的看注释,值得一提的是==》reconfigure with override,上面一句语句如果不加这句,则只是临时可用,不会影响系统原有配置(可以理解为==》不加就是new和加了就是override

    代码贴上:

    --创建目录(如果指定的路径不存在就会报错)
    exec sp_configure 'show advanced options',1 --显示高级选项
    reconfigure with override--重新配置
        exec sp_configure 'xp_cmdshell',1 --1代表允许,0代表阻止
        reconfigure with override
            exec xp_cmdshell 'mkdir F:WorkSQL mkdir E:SQL'
        exec sp_configure 'xp_cmdshell',0
        reconfigure with override
    exec sp_configure 'show advanced options',0
    reconfigure with override
    View Code

    SQL也贴上吧,比较这玩意总得有个语境吧:

    --如果数据库存在就删除
    use master
    if exists(select * from sysdatabases where Name=N'LawyerBlog')
    begin
    drop database LawyerBlog
    end
    
    --创建目录(如果指定的路径不存在就会报错)
    exec sp_configure 'show advanced options',1 --显示高级选项
    reconfigure with override--重新配置
        exec sp_configure 'xp_cmdshell',1 --1代表允许,0代表阻止
        reconfigure with override
            exec xp_cmdshell 'mkdir F:WorkSQL mkdir E:SQL'
        exec sp_configure 'xp_cmdshell',0
        reconfigure with override
    exec sp_configure 'show advanced options',0
    reconfigure with override
    
    --创建数据库
    create database LawyerBlog
    on primary                    --数据库文件,主文件组
    (
        name='LawyerBlog_Data', --逻辑名
        size=10mb,                --初始大小
        filegrowth=10%,            --文件增长
        maxsize=1024mb,            --最大值
        filename=N'F:WorkSQLLawyerBlog_Data.mdf'--存放路径(包含文件后缀名)
    ),
    filegroup ArticleData --Article文件组(表创建到不同的文件组里面可以分担压力)
    (
        name='LawyerBlog_Data_Article',
        size=10mb,
        filegrowth=10%,
        maxsize=1024mb,
        filename=N'E:SQLLawyerBlog_Data_Article.ndf'
    )
    log on --日记
    (
        name='LawyerBlog_Log1',
        size=5mb,
        filegrowth=5%,
        filename=N'F:WorkSQLLawyerBlog_log1.ldf'
    ),
    (
        name='LawyerBlog_Log2',
        size=5mb,
        filegrowth=5%,
        filename=N'E:SQLLawyerBlog_log2.ldf'
    )
    go
    View Code

    扩展:

    如果是普通用户要有ALTER SETTINGS权限才能运行sp_configure(一般管理员才有这个权限)

    向数据库添加数据文件或日志文件

    1. 连接到数据库引擎。

    2. 在标准菜单栏上,单击“新建查询”

    3. 将以下示例复制并粘贴到查询窗口中,然后单击“执行”此实例向数据库添加由两个文件组成的文件组。此示例在 AdventureWorks2012 数据库中创建文件组 Test1FG1,然后将两个 5MB 的文件添加到该文件组。

      USE master
      GO
      ALTER DATABASE AdventureWorks2012
      ADD FILEGROUP Test1FG1;
      GO
      ALTER DATABASE AdventureWorks2012 
      ADD FILE 
      (
          NAME = test1dat3,
          FILENAME = 'C:Program FilesMicrosoft SQL ServerMSSQL10_50.MSSQLSERVERMSSQLDATA	1dat3.ndf',
          SIZE = 5MB,
          MAXSIZE = 100MB,
          FILEGROWTH = 5MB
      ),
      (
          NAME = test1dat4,
          FILENAME = 'C:Program FilesMicrosoft SQL ServerMSSQL10_50.MSSQLSERVERMSSQLDATA	1dat4.ndf',
          SIZE = 5MB,
          MAXSIZE = 100MB,
          FILEGROWTH = 5MB
      )
      TO FILEGROUP Test1FG1;
      GO
      View Code
  • 相关阅读:
    Solaris 默认Shell 修改
    关系数组
    文件描述符 文件操作 <> open 文件句柄
    IO 双引号 输出 输入
    第五章答案
    子例程 subroutine
    钻石操作符
    花括号的使用 printf %${width}s , 否则会 去找 $widths
    print reverse <> 是打印全部的文件内容 ?
    hihoCoder#1239 Fibonacci
  • 原文地址:https://www.cnblogs.com/dunitian/p/5253612.html
Copyright © 2020-2023  润新知