sql docker容器

This guide shows you how to use Docker to pull a MSSQL Server image and run it. Azure Data Studio is a cross-platform database tool that will be using to connect our Docker container with MSSQL and execute SQL statements.

本指南向您展示如何使用Docker提取并运行MSSQL Server映像。 Azure Data Studio是一个跨平台的数据库工具,将用于将Docker容器与MSSQL连接并执行SQL语句。

At the end, I will show you how to import a database to the Docker file system so that you can access it through Azure Data Studio.

最后,我将向您展示如何将数据库导入Docker文件系统,以便您可以通过Azure Data Studio访问它。

Check out other related guides here:

在此处查看其他相关指南:

  • How to Connect your AWS RDS Microsoft SQL Server using Azure Data Studio

    如何使用Azure Data Studio连接AWS RDS Microsoft SQL Server

  • How to Import a Sample Database to your AWS RDS Microsoft SQL Server using S3

    如何使用S3将示例数据库导入到AWS RDS Microsoft SQL Server

We will be touching on the technologies shown below:

我们将涉及以下技术:

  • Database: Microsoft SQL Server数据库:Microsoft SQL Server
  • Container to pull mssql-server-demo: Docker提取mssql-server-demo的容器:Docker
  • Installer for mssql-cli: Node.js (Run-time Environment) / Node Package Manager (NPM)mssql-cli的安装程序:Node.js(运行时环境)/ Node Package Manager(NPM)
  • Database tool and GUI: Azure Data Studio数据库工具和GUI:Azure Data Studio

使用Docker构建环境 (Building our Environment with Docker )

安装Docker (Installing Docker)

Full guide for this portion here:

这部分的完整指南在这里 :

  1. Download Docker CE (Community Edition) for Mac here.

    在此处下载适用于Mac的Docker CE(社区版)。

  2. To install, double-click on the .dmg file and then drag the Docker application icon to your Application folder.要安装,请双击.dmg文件,然后将Docker应用程序图标拖到您的Application文件夹中。

什么是Docker? (What is Docker?)

Docker is a platform that enables software to run in its own isolated environment. SQL Server (from 2017) can be run on Docker in its own isolated container.

Docker是一个平台,使软件可以在自己的隔离环境中运行。 SQL Server(自2017年起)可以在Docker的隔离容器中运行。

Once Docker is installed, you simply download — or “pull” — the SQL Server on Linux Docker Image to your Mac, then run it as a Docker container. This container is an isolated environment that contains everything SQL Server needs to run.

一旦安装了Docker,您只需将Linux Docker Image上SQL Server下载(或“拉”)到Mac,然后将其作为Docker容器运行。 此容器是一个隔离的环境,其中包含SQL Server需要运行的所有内容。

启动Docker (Launch Docker)

Open your Docker application, it should be located in the Applications folder.

打开您的Docker应用程序,它应该位于Applications文件夹中。

增加记忆 (Increase the Memory)

By default, Docker will have 2GB of memory allocated to it. SQL Server needs at least 3.25GB. To be safe, increase it to 4GB if you can. Since this is just a playground, 2GB should be enough.

默认情况下,Docker将为其分配2GB的内存。 SQL Server至少需要3.25GB。 为了安全起见,请尽可能将其增加到4GB。 由于这只是一个游乐场,因此2GB应该足够了。

可选-如果您要增加内存大小: (Optional - in case you want to increase memory size:)

  1. Select Preferences from the little Docker icon in the top menu从顶部菜单中的Docker小图标中选择偏好设置
  2. Slide the memory slider up to at least 2GB将内存滑块向上滑动至少2GB
  3. Click Apply & Restart单击“应用并重新启动”

下载SQL Server (Download SQL Server)

Open a Terminal window and run the following command.

打开一个终端窗口,然后运行以下命令。

sudo docker pull mcr.microsoft.com/mssql/server:2019-latest

This downloads the latest SQL Server 2019 for Linux Docker image to your computer.

这会将最新SQL Server 2019 for Linux Docker映像下载到您的计算机。

You can also check for the latest container version on the Docker website if you wish.

您也可以根据需要在Docker网站上检查最新的容器版本 。

启动Docker映像 (Launch Docker Image)

Run the following command to launch an instance of the Docker image you just downloaded:

运行以下命令以启动您刚刚下载的Docker映像的实例:

docker run -d --name sql_server_demo -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=really

Example output:

输出示例:

检查Docker容器(可选) (Check the Docker container (optional))

You can type the following command to check that the Docker container is running.

您可以键入以下命令来检查Docker容器是否正在运行。

docker ps

If it’s up and running, it should return something like this:

如果启动并运行,它将返回以下内容:

If you accidentally closed your Docker App, open your terminal and type

如果您不小心关闭了Docker App,请打开终端并输入

docker start sql_server_demo

安装Node.js和NPM (Install the Node.js and NPM)

Check if you have Node.js and NPM. Run the following commands in your terminal.

检查您是否具有Node.js和NPM。 在终端中运行以下命令。

node -v
npm -v

If you get an output with a version number, skip the rest of this section.

如果您获得带有版本号的输出,请跳过本节的其余部分。

Then visit the Node.js website by clicking the following link:

然后通过单击以下链接访问Node.js网站:

https://nodejs.org/en/

https://nodejs.org/en/

Click the LTS version (the version number may be various) download button to download the Node.js package:

单击LTS版本(版本号可能不同)下载按钮以下载Node.js软件包:

Next click and run the package after downloading. MacOS and Windows will have different installation process. Please follow the instruction to install the Node.js.

下载后,单击下一步并运行包。 MacOS和Windows将具有不同的安装过程。 请按照说明安装Node.js。

Then test again if Node.js and NPM were installed successfully by running the following commands in the terminal:

然后通过在终端中运行以下命令来再次测试Node.js和NPM是否已成功安装:

node -v
npm -v

An output should look like this:

输出应如下所示:

安装sql-cli (Install sql-cli)

Run the following command to install the sql-cli command line tool. This tool allows you to run queries and other commands against your SQL Server instance.

运行以下命令以安装sql-cli命令行工具。 使用此工具,您可以对SQL Server实例运行查询和其他命令。

npm install -g sql-cli

If you get a permission error, use the sudo command:

如果出现权限错误,请使用sudo命令:

sudo npm install -g sql-cli

连接到MSSQL Server (Connect to MSSQL Server)

Connect to your SQL Server using the mssql command, followed by the username and password parameters. Syntax: -u <username> -p <password>

使用mssql命令以及用户名和密码参数连接到SQL Server。 语法:-u <用户名> -p <密码>

mssql -u sa -p reallyStrongPwd123

Your output should look like this if you successfully connected:

如果成功连接,您的输出应如下所示:

运行快速测试 (Run a Quick Test)

Run a quick test to check if you can connect to your SQL Server. Use the following SQL statement to check your SQL Server version:

运行快速测试以检查是否可以连接到SQL Server。 使用以下SQL语句检查您SQL Server版本:

SELECT @@VERSION;

If it’s running, you should see something like this:

如果正在运行,您应该会看到类似以下内容:

下载SQL Server GUI-Azure Data Studio (Download an SQL Server GUI - Azure Data Studio)

Azure Data Studio (formerly SQL Operations Studio) is a free GUI management tool that you can use to manage SQL Server on your computer. You can use it to create and manage databases, write queries, backup and restore databases, and more.

Azure Data Studio (以前称为SQL Operations Studio)是一个免费的GUI管理工具,可用于管理计算机上SQL Server。 您可以使用它来创建和管理数据库,编写查询,备份和还原数据库等等。

Azure Data Studio is available on Windows, Mac and Linux.

Windows,Mac和Linux上都可以使用Azure Data Studio。

安装Azure Data Studio (Install Azure Data Studio)

To install Azure Data Studio onto your Mac:

要将Azure Data Studio安装到您的Mac上:

  1. Visit the Azure Data Studio download page, and click the .zip file for macOS

    访问Azure Data Studio下载页面 ,然后单击macOS的.zip文件

  2. Once the .zip file has finished downloading, double click it to expand its contents.zip文件下载完成后,双击它以展开其内容
  3. Drag the .app file to the Applications folder (the file will probably be called Azure Data Studio.app)

    将.app文件拖到 Applications文件夹中(该文件可能称为Azure Data Studio.app )

连接到SQL Server (Connect to SQL Server)

Now that Azure Data Studio is installed, you can use it to connect to SQL Server.

现在已经安装了Azure Data Studio,您可以使用它来连接到SQL Server。

  1. Launch Azure Data Studio. It is located in your Applications folder.启动Azure Data Studio。 它位于您的应用程序文件夹中。
  2. Enter the login credentials and other information for the SQL Server instance that you’d like to connect to:输入您要连接SQL Server实例的登录凭据和其他信息:

It should look similar to this:

它看起来应该类似于:

It should look similar to this:

它看起来应该类似于:

  • Server Name: localhost, [port number]

    服务器名称 :本地主机,[端口号]

    Server Name: localhost, [port number] Example: localhost, 1433

    服务器名称 :本地主机,[端口号] 示例 :本地主机,1433

  • Authentication Type: SQL Login

    身份验证类型 :SQL登录

  • User name: [your SQL Server username] or sa

    用户名 :[您SQL Server用户名]或sa

  • Password: [your SQL Server password] or reallyStrongPwd123

    密码 :[您SQL Server密码]或trueStrongPwd123

  • Database Name: <default>

    数据库名称 :<默认>

  • Server Group: <default>

    服务器组 :<默认>

If you use a port other than the default 1433, click Advanced and enter it in the Port field.

如果使用默认端口1433以外的端口,请单击“高级”,然后在“端口”字段中输入该端口。

Alternatively, you can append it to your server name with a comma in between. For example, if you used port 1400, type in localhost,1400.

或者,您可以将其附加到服务器名称,中间使用逗号。 例如,如果您使用端口1400,则键入localhost,1400。

You can now go ahead and create databases, run scripts, and perform other SQL Server management tasks.

现在,您可以继续创建数据库,运行脚本并执行其他SQL Server管理任务。

  1. Click New Query

    点击新查询

2.     Type SELECT @@VERSION, then Click Run Query.

2.键入SELECT @@ VERSION ,然后单击“运行查询”

You should be able to see: Microsoft SQL Server in the Results.

您应该能够看到:结果中的Microsoft SQL Server

使用Azure Data Studio将示例数据库导入到SQL Server (Importing a sample database to your SQL Server using Azure Data Studio)

下载示例数据库文件AdventureWorks (Download the sample database file AdventureWorks)

To get the OLTP downloads of AdventureWorks, go to this link and choose any sample database. In my example, I choose AdventureWorks2017.bak. We will upload this to the S3 Bucket.

要获得AdventureWorks的OLTP下载,请转到此链接并选择任何示例数据库。 在我的示例中,我选择AdventureWorks2017.bak 。 我们将其上传到S3存储桶。

将文件复制到您的Docker (Copying the file to your docker)

Type the following command in the terminal following this syntax:

使用以下语法在终端中键入以下命令:

docker cp <location_of_file> <container_id>:/var/opt/mssql/data

It should look like this:

它看起来应该像这样:

If you forgot your container id, use the docker ps command.

如果您忘记了容器ID,请使用docker ps命令。

在Docker中导入示例数据库 (Importing the sample database in Docker)

Go to Azure Data Studio, and click the localhost, 1443, then choose Restore.

转到Azure Data Studio,然后单击localhost 1443 ,然后选择“还原”

Then choose Backup file as the selection for Restore from. Next, click the blue button on the right of Backup file path.

然后选择“ 备份文件”作为“从中还原”的选择。 接下来,单击“ 备份文件路径 ”右侧的蓝色按钮

Look for the sample database file. It should be located in

查找示例数据库文件。 它应该位于

/var/opt/mssql/data/AdventureWorks2017.bak

Choose Restore.

选择还原

Check your localhost, 1443. It should generated a Database named AdventureWorks2017 and have contents such as Tables and Views. If not, right-click on localhost, 1443 and choose Refresh. You can also restart your Azure Data Studio application.

检查您的本地主机1443。它应该生成一个名为AdventureWorks2017的数据库,并具有诸如表和视图之类的内容。 如果不是,请右键单击localhost 1443,然后选择“刷新”。 您也可以重新启动Azure Data Studio应用程序。

测试样本数据库 (Testing the sample database)

  1. Choose AdventureWorks2017 from the dropdown menu.

    从下拉菜单中选择AdventureWorks2017

  2. Write a SQL query:编写一个SQL查询:
SELECT * FROM HumanResources.Department;

3.   Click Run to run the query.

3.单击运行以运行查询。

You should have an output like this:

您应该具有以下输出:

Congratulations!

sql docker容器_如何将Microsoft SQL Server Docker容器与Azure Data Studio连接相关推荐

  1. 【Microsoft Azure 的1024种玩法】三十. 使用Azure Data Studio之快速上手连接管理Azure SQL 数据库(一)

    [简介] Azure Data Studio 是一种跨平台的数据库工具,适合在 Windows.macOS 和 Linux 上使用本地和云数据平台的数据专业人员,Azure Data Studio 利 ...

  2. sql azure 语法_使用Azure Data Studio从SQL Server数据创建图表

    sql azure 语法 In this article, we will explore charts in an Azure Data Studio using data stored in SQ ...

  3. sql azure 语法_深入了解Azure Data Studio:扩展和Azure SQL DB开发

    sql azure 语法 In the previous articles listed below, we went through the Azure Data Studio tool, star ...

  4. 具有Ubuntu和Azure Data Studio的Linux上SQL Server 2019

    In the previous articles of this series on using SQL Server 2019 on Ubuntu, we have explored the fol ...

  5. azure 使用_使用Azure Data Studio开始您的旅程

    azure 使用 In this article, we will introduce the Azure Data Studio in a way that makes it easy for yo ...

  6. sql azure 语法_在Azure Data Studio中计划SQL笔记本

    sql azure 语法 SQL Notebooks are an interactive way of creating documents, executing T-SQL queries alo ...

  7. sql azure 语法_在Azure Data Studio中学习用于SQL Notebook的Markdown语言

    sql azure 语法 Microsoft supports SQL Notebooks in Azure Data Studio. It is an exciting feature that a ...

  8. sql azure 语法_方便SQL笔记本,用于在Azure Data Studio中进行故障排除

    sql azure 语法 This article prepares a handy SQL Notebook for DBAs. You can use this notebook to troub ...

  9. sql azure 语法_使用Azure Data Studio开发SQL Server数据库

    sql azure 语法 In the previous article, Starting your journey with Azure Data Studio, we put the first ...

  10. ssms脚本生成缓慢_使用SSMS和Azure Data Studio生成数据脚本

    ssms脚本生成缓慢 This article explores different ways to generate data scripts using Azure Data Studio and ...

最新文章

  1. 一致性哈希算法以及其PHP实现
  2. mongodb 开启身份认证_Yum安装mongodb及开启用户认证远程登录
  3. x和伪全面屏(18:9)关于图片切片有白条
  4. 小波说雨燕 第三季 构建 swift UI 之 UI组件集-视图集(一)视图共性 学习笔记...
  5. swiper踩过的哪些坑
  6. centos 下安装 mysql 5.6
  7. I.MX6 dhcpcd 需要指定网卡
  8. 易用性软件测试用例,易用性、界面测试用例
  9. php实现酒店客房管理系统,基于ssh/jsp/java/asp.net/php的酒店客房管理系统
  10. 人脸对齐 matlab,常用几种人脸对齐算法ASM/AAM/CLM/SDM
  11. 清理winsxs的小工具
  12. rrweb学习案例(网页录制,回放)-demo
  13. 程序猿生存指南-43 温柔以待
  14. 电脑改成,如何把电脑变成无线路由器
  15. POJ - Frogs' Neighborhood(Havel-Hakimi)
  16. KDD 2020阿里巴巴论文一分钟秒读
  17. 数据分析师是如何被淘汰的?
  18. 蚂蚁金服“定损宝”现身AI顶级会议NeurIPS 1
  19. 如何进行团队建设以保持团队稳定?
  20. MQTT客户端(基于mosquitto库)上报温度到腾讯云

热门文章

  1. Spring学习笔记4
  2. 在线算法 离线算法
  3. deepin系统屏幕闪烁问题解决
  4. MTk kernel启动流程
  5. CentOS7设置console口能连接
  6. 什么是常见的计算机应用软件,什么是计算机的应用软件?
  7. linux如何上传数据到百度网盘,Linux命令行上传文件到百度网盘
  8. 烟大计算机考研二战,以坚持铺就考研之路——记经济管理学院考研优秀个人程林林...
  9. 【保姆级】网络安全工程师学习成长路线,就业前景,薪资待遇分享
  10. Java 打开资源管理器