SqlServer教程

win10,docker安装sqlServer2017,并导入备份数据bak

本文主要是介绍win10,docker安装sqlServer2017,并导入备份数据bak,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一、docker安装sqlServer2017

  1. 拉取镜像

    docker pull mcr.microsoft.com/mssql/server:2017-latest
    
  2. 启动

    docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=wade@123" -p 1433:1433 -v D:/database/data:/var/opt/mssql/data --name sqlserver -d mcr.microsoft.com/mssql/server:2017-latest
    

    *密码设置不能太简单,不然启动失败

    *挂载目录:D:/database/data

二、导入备份数据

  1. 将数据上传至容器

    docker cp 备份文件路径 sqlserver:/usr/local
    
  2. 进入容器

    docker exec -it sqlserver bash
    
  3. 输入对应账号密码进入

    /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "wade@123"
    
  4. 查询文件的逻辑名

    RESTORE FILELISTONLY FROM DISK = '/usr/local/备份文件.bak'
    
    • 结果(LogicalName):

      TeamUPDB_INSTALL_1 
      TeamUPDB_INSTALL_1_log 
      
  5. 使用RESTORE DATABASE命令还原数据库

RESTORE DATABASE mytest
FROM DISK = '/usr/local/OA2007DB_NEW.bak'
WITH 
MOVE 'TeamUPDB_INSTALL_1' TO '/var/opt/mssql/data/mytest.mdf',
MOVE 'TeamUPDB_INSTALL_1_log' TO '/var/opt/mssql/data/mytest.ldf',
NOUNLOAD, REPLACE
GO
这篇关于win10,docker安装sqlServer2017,并导入备份数据bak的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!