具有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 following

在本系列的上一篇有关在Ubuntu上使用SQL Server 2019的文章中,我们探讨了以下内容

Previously, in part 2 of this series, we connected SQL Server 2019 from outside the virtual machine. Now, let us see how we can install SQL Server from inside the virtual machine running Ubuntu operating system.

之前,在本系列的第2部分中,我们从虚拟机外部连接了SQL Server 2019。 现在,让我们看看如何从运行Ubuntu操作系统的虚拟机内部安装SQL Server。

SQL Server now installs on both the Windows and the Linux platforms. Normally, we used to connect to SQL Server with SQL Server Management Studio. We can connect to SQL Server on Linux using SQL Server Management Studio, but it cannot be installed on the Linux operating system directly. Further, in the article, we will install following cross-platform tools which can be installed on both Windows and Linux operating systems.

现在,SQL Server可以在Windows和Linux平台上安装。 通常,我们以前使用SQL Server Management Studio连接到SQL Server。 我们可以使用SQL Server Management Studio连接到Linux上SQL Server,但是不能将其直接安装在Linux操作系统上。 此外,在本文中,我们将安装以下跨平台工具,这些工具可以安装在Windows和Linux操作系统上。

  • Azure Data Studio

    Azure数据工作室
  • SQLCMD

    SQLCMD
  • mssql-cli

    mssql-cli

在Ubuntu 18.10上安装Azure Data Studio (Azure Data Studio installation on Ubuntu 18.10)

Azure Data Studio is a cross-platform database tool, which works on both the Windows as well as on the Linux operating system. In September 2018, Microsoft released the general availability release of Azure Data Studio. Previously, it was running with the name SQL Operations Studio. In the previous article, we connected SQL Server running on Ubuntu 18.0 through Azure Data Studio installed on the Windows operating system.

Azure Data Studio是一个跨平台的数据库工具,可以在Windows以及Linux操作系统上运行。 Microsoft在2018年9月发布了Azure Data Studio的常规可用性版本。 以前,它以SQL Operations Studio的名称运行。 在上一篇文章中,我们通过Windows操作系统上安装的Azure Data Studio连接了在Ubuntu 18.0上运行SQL Server。

We can install Azure Data Studio on Ubuntu 18.10 using both the GUI and command line mode as well. Let us install the tool using the GUI mode. To do so, open the browser (by default Mozilla is installed on Ubuntu OS) and go to this URL.

我们也可以使用GUI和命令行模式在Ubuntu 18.10上安装Azure Data Studio。 让我们使用GUI模式安装该工具。 为此,请打开浏览器(默认情况下,Ubuntu OS上安装了Mozilla)并转到该URL

In Linux, we can see a different kind of download available

在Linux中,我们可以看到另一种下载类型

  • Deb (Debian software repository)

    Deb(Debian软件存储库)
  • Rpm: Package in .rpm format

    Rpm:.rpm格式的软件包
  • Tar.gz: Files in a compressed format

    Tar.gz:压缩格式的文件

In this example, we will perform the Debian installation for the Azure Data Studio. It is a graphical method to perform the installation on Ubuntu. Download the .deb file and save it in the desired location.

在此示例中,我们将为Azure Data Studio执行Debian安装。 这是在Ubuntu上执行安装的一种图形方法。 下载.deb文件,并将其保存在所需的位置。

Once Debian package (azuredatastudio-Linux-1.2.4.deb) download is successful, double-click on the file to launch the installation as shown below.

成功下载Debian软件包(azuredatastudio-Linux-1.2.4.deb)后,双击文件以启动安装,如下所示。

We get the summary of the product description along with the version, size, source, and the license information. Click on ‘Install’ box in the top showing in the green colored box.

我们获得产品说明的摘要以及版本,大小,来源和许可证信息。 单击顶部显示为绿色的“安装”框。

Before installation, authentication is required for this. Enter the administrator user id and password we created while installing Ubuntu 18.10.

安装之前,需要进行身份验证。 输入我们在安装Ubuntu 18.10时创建的管理员用户ID和密码。

It begins the installation and you can see the progress of the installation.

它开始安装,您可以看到安装进度。

Once the installation is complete, you did not get any completion or successful installation message here. Instead, you can see the ‘Remove’ box in red color. It shows that we have installed Azure Data Studio successfully.

安装完成后,您在此处没有收到任何完成或成功安装的消息。 相反,您可以看到红色的“删除”框。 它表明我们已经成功安装了Azure Data Studio。

In the Ubuntu application, you can verify the Azure Data Studio is present.

在Ubuntu应用程序中,您可以验证Azure Data Studio是否存在。

Double click on it to launch the Azure Data Studio initial screen.

双击它以启动Azure Data Studio初始屏幕。

Enter the connection details like instance name, authentication method (SQL authentication), database name (if we want to connect to the specific database) and the server group.

输入连接详细信息,例如实例名称,身份验证方法(SQL身份验证),数据库名称(如果我们要连接到特定数据库)和服务器组。

And we are connected to the SQL Server preview version from inside the virtual machine hosting Ubuntu 18.10. You can verify the server instance version, edition, computer name from the server dashboard launched after connecting to the SQL Server.

而且我们从托管Ubuntu 18.10的虚拟机内部连接到SQL Server预览版。 您可以从连接到SQL Server之后启动的服务器仪表板中验证服务器实例的版本,版本,计算机名称。

Go to ‘Help -> About’ to get details about Azure Data Studio version.

转到“帮助->关于”以获取有关Azure Data Studio版本的详细信息。

Now, we can use the Azure Data Studio to connect to SQL Server and run queries in Linux.

现在,我们可以使用Azure Data Studio连接到SQL Server并在Linux中运行查询。

Ubuntu上SQLCMD (SQLCMD on the Ubuntu )

SQLCMD is the default command line tool to connect with SQL Server on the command line mode. In Ubuntu, to connect SQL Server first start an interactive session and then connect to SQL Server with the credentials.

SQLCMD是在命令行模式下与SQL Server连接的默认命令行工具。 在Ubuntu中,要连接SQL Server,首先要启动一个交互式会话,然后使用凭据连接到SQL Server。

  • sudo docker exec -it sql1 “bash”

    sudo docker exec -it sql1“ bash”
  • /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ‘password’

    / opt / mssql-tools / bin / sqlcmd -S本地主机-U SA -P'密码'

It connects to SQL Server and we get the next line prompt as ‘>’

它连接到SQL Server,我们得到下一行提示为'>'

Let check basis SQL query to check the version of SQL Server. Therefore, run the below query.

让我们检查基础SQL查询来检查SQL Server的版本。 因此,运行以下查询。

1>select @@version

1>选择@@ version

2>go

2>开始

You can see the output in the below image.

您可以在下图中看到输出。

SQLCMD works in the Linux operating system similar to the windows version.

SQLCMD在类似于Windows版本的Linux操作系统中工作。

Ubuntu上的MSSQL-CLI (MSSQL-CLI on Ubuntu )

Instead of using SQLCMD, we can use an interactive command line tool ‘mssql-cli’. It is an open -source (BSD 3 license) tool based on the python. We can install ‘mssq-cli’ on the windows, Linux and the Mac OS. The source code for this tool is on GitHub.

除了使用SQLCMD,我们还可以使用交互式命令行工具“ mssql-cli”。 它是基于python的开源(BSD 3许可证)工具。 我们可以在Windows,Linux和Mac OS上安装“ mssq-cli”。 该工具的源代码在GitHub上

Open the link in the Mozilla browser inside the virtual machine. Here you see, mssql-cli version for different operating systems.

在虚拟机内部的Mozilla浏览器中打开链接 。 在这里,您可以看到针对不同操作系统的mssql-cli版本。

Click on the ‘Direct downloads’ in the bottom side of the page and download the .deb version of the tool mssql-cli.

单击页面底部的“直接下载”,然后下载工具mssql-cli的.deb版本。

Save the file on the desired location.

将文件保存在所需的位置。

Go the download folder and double click on the file to launch it. It opens the below screen, click on ‘Install’.

转到下载文件夹,然后双击该文件以启动它。 它将打开以下屏幕,单击“安装”。

Enter the credentials for the authentication.

输入身份验证的凭据。

Track the progress of the ‘mssql-cli’ installation.

跟踪“ mssql-cli”的安装进度。

Similar to the Azure Data Studio, we can see that the after product installation we do not get any messages.

与Azure Data Studio相似,我们可以看到在产品安装后我们没有收到任何消息。

Open terminal inside the virtual machine and type ‘mssql-cli’

在虚拟机内部打开终端,然后键入“ mssql-cli”

Provide the username and the password. By default, it takes the username ‘sa’.

提供用户名和密码。 默认情况下,它采用用户名“ sa”。

Enter the password and we can see basic details about this tool.

输入密码,我们将看到有关此工具的基本详细信息。

  • Version: 0.15.0

    版本:0.15.0
  • Mail:sqlcli@microsoft.com

    邮件:sqlcli@microsoft.com
  • Home: http://github.com/dbcli/mssql-cli

    主页:http://github.com/dbcli/mssql-cli

If connected to the SQL instance and by default show prompt for the ‘master’ database.

如果已连接到SQL实例,并且默认情况下显示“ master”数据库的提示。

Master>

大师>

You can start writing query interactively here i.e. you get inline suggestions as soon you go forward with writing a query.

您可以在此处开始以交互方式编写查询,即,只要继续编写查询,您就会获得内联建议。

We get query output also in the proper format as compared to the sqlcmd tool.

与sqlcmd工具相比,我们还以正确的格式获取查询输出。

We have explored the cross-platform tools to connect to SQL Server. Now let us export the data from the SQL Server running on windows to SQL Server on Linux using the Import and Export wizard.

我们已经探索了跨平台的工具来连接到SQL Server。 现在,让我们使用“导入和导出”向导将数据从Windows上运行SQL Server导出到Linux上SQL Server。

Launch the Import and Export wizard as shown here.

启动导入和导出向导,如下所示。

In the next step, choose a data source. For our example, the data source is SQL Server 2019 running on Windows OS and the database WideWorldmporters.

在下一步中,选择一个数据源。 对于我们的示例,数据源是在Windows OS和数据库WideWorldmporters上运行SQL Server 2019。

Click on ‘Next’ and in the destination give the SQL Server instance on the Ubuntu which we created in this part.

单击“下一步”,然后在目标位置中提供我们在此部分中创建的Ubuntu上SQL Server实例。

Select the tables and the views, let us select all objects in the list and click Next.

选择表和视图,让我们选择列表中的所有对象,然后单击“下一步”。

We can either run the package or save it for later work.

我们可以运行该程序包或将其保存以供以后工作。

Review the actions so far.

查看到目前为止的操作。

Click on ‘Finish’ to start data export to SQL Server on Ubuntu. You can see the progress of the individual tables export data.

单击“完成”以开始将数据导出到Ubuntu上SQL Server。 您可以看到各个表导出数据的进度。

Once completed, we can see the ‘Success’ message along with the number of rows transferred for each table.

完成后,我们可以看到“成功”消息以及为每个表传输的行数。

We can see here that we can access the SQL Server on Linux similar to Windows version and data can be transferred easily.

我们可以在这里看到,我们可以在Linux上访问类似于Windows版本SQL Server,并且可以轻松地传输数据。

As stated above, SQL Server Management Studio can be used to connect to SQL Server on Linux from outside the Ubuntu operating system and verify the top tables which we imported from the WideWorldmporters database.

如上所述,SQL Server Management Studio可用于从Ubuntu操作系统外部连接到Linux上SQL Server,并验证我们从WideWorldmporters数据库导入的顶级表。

结论 (Conclusion)

In this article, we have installed SQL Server on Ubuntu and explored various tools to connect to SQL Server.

在本文中,我们已在Ubuntu上安装了SQL Server,并探索了各种工具来连接到SQL Server。

目录 (Table of contents)

SQL Server 2019 on Linux with Ubuntu and Azure Data Studio
SQL Server 2019 on Linux with a Docker container on Ubuntu
SQL Server 2019 on Linux with Ubuntu
SQL Server 2019 installation on Ubuntu without a Docker Container
Renaming Logical and Physical file names in SQL Server on Linux
Rename SQL Server instance on Ubuntu Linux
具有Ubuntu和Azure Data Studio的Linux上SQL Server 2019
Linux上SQL Server 2019和Ubuntu上的Docker容器
Linux与Ubuntu上SQL Server 2019
在没有Docker容器的Ubuntu上安装SQL Server 2019
在Linux上SQL Server中重命名逻辑和物理文件名
在Ubuntu Linux上重命名SQL Server实例

翻译自: https://www.sqlshack.com/sql-server-2019-on-linux-with-ubuntu-and-azure-data-studio/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值