Sql linux ������� ����

Quickstart: Install SQL Server and create a database on Ubuntu

Applies to: SQL Server (all supported versions) — Linux

In this quickstart, you install SQL Server 2017 on Ubuntu 16.04/18.04. You then connect with sqlcmd to create your first database and run queries.

This tutorial requires user input and an internet connection. If you are interested in the unattended or offline installation procedures, see Installation guidance for SQL Server on Linux. For a list of supported platforms, see our Release notes.

In this quickstart, you install SQL Server 2019 on Ubuntu 16.04, 18.04, or 20.04. You then connect with sqlcmd to create your first database and run queries.

Ubuntu 20.04 is supported starting with SQL Server 2019 CU10.

This tutorial requires user input and an internet connection. If you are interested in the unattended or offline installation procedures, see Installation guidance for SQL Server on Linux. For a list of supported platforms, see our Release notes.

Prerequisites

You must have an Ubuntu 16.04 or 18.04 machine with at least 2 GB of memory.

To install Ubuntu 18.04 on your own machine, go to http://releases.ubuntu.com/bionic/. You can also create Ubuntu virtual machines in Azure. See Create and Manage Linux VMs with the Azure CLI.

At this time, the Windows Subsystem for Linux for Windows 10 is not supported as an installation target for production workloads.

Ubuntu 18.04 is supported starting with SQL Server 2017 CU20. If you want to use the instructions on this article with Ubuntu 18.04, make sure you use the correct repository path, 18.04 instead of 16.04 .

If you are running SQL Server on a lower version, the configuration is possible with modifications.

You must have an Ubuntu 16.04, 18.04, or 20.04 machine with at least 2 GB of memory.

To install Ubuntu 20.04 on your own machine, go to https://releases.ubuntu.com/20.04/. You can also create Ubuntu virtual machines in Azure. See Create and Manage Linux VMs with the Azure CLI.

At this time, the Windows Subsystem for Linux for Windows 10 is not supported as an installation target for production workloads.

Install SQL Server

The following commands for SQL Server 2017 points to the Ubuntu 18.04 repository. If you are using Ubuntu 16.04, change the path below to /ubuntu/16.04/ instead of /ubuntu/18.04/ .

To configure SQL Server on Ubuntu, run the following commands in a terminal to install the mssql-server package.

Import the public repository GPG keys:

Register the Microsoft SQL Server Ubuntu repository:

For Ubuntu 16.04:

For Ubuntu 18.04:

If you want to install SQL Server 2019 , you must instead register the SQL Server 2019 repository. Use the following command for SQL Server 2019 installations:

For Ubuntu 16.04:

For Ubuntu 18.04:

Run the following commands to install SQL Server:

After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition.

The following SQL Server 2017 editions are freely licensed: Evaluation, Developer, and Express.

Make sure to specify a strong password for the SA account (Minimum length 8 characters, including uppercase and lowercase letters, base 10 digits and/or non-alphanumeric symbols).

Once the configuration is done, verify that the service is running:

If you plan to connect remotely, you might also need to open the SQL Server TCP port (default 1433) on your firewall.

At this point, SQL Server is running on your Ubuntu machine and is ready to use!

Install SQL Server

The following commands for SQL Server 2019 points to the Ubuntu 20.04 repository. If you are using Ubuntu 18.04 or 16.04, change the path below to /ubuntu/18.04/ or /ubuntu/16.04/ instead of /ubuntu/20.04/ .

To configure SQL Server on Ubuntu, run the following commands in a terminal to install the mssql-server package.

Import the public repository GPG keys:

Register the Microsoft SQL Server Ubuntu repository for SQL Server 2019:

For Ubuntu 16.04:

For Ubuntu 18.04:

For Ubuntu 20.04:

Run the following commands to install SQL Server:

After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition.

Читайте также:  Windows не может распознать принтер

Make sure to specify a strong password for the SA account (Minimum length 8 characters, including uppercase and lowercase letters, base 10 digits and/or non-alphanumeric symbols).

Once the configuration is done, verify that the service is running:

If you plan to connect remotely, you might also need to open the SQL Server TCP port (default 1433) on your firewall.

At this point, SQL Server 2019 is running on your Ubuntu machine and is ready to use!

Install the SQL Server command-line tools

To create a database, you need to connect with a tool that can run Transact-SQL statements on the SQL Server. The following steps install the SQL Server command-line tools: sqlcmd and bcp.

Use the following steps to install the mssql-tools on Ubuntu.

By default, curl isn’t installed on Ubuntu. To install curl, run this code:

Import the public repository GPG keys.

Register the Microsoft Ubuntu repository.

For Ubuntu 16.04:

For Ubuntu 18.04:

For Ubuntu 20.04:

Update the sources list and run the installation command with the unixODBC developer package. For more information, see Install the Microsoft ODBC driver for SQL Server (Linux).

To update to the latest version of mssql-tools run the following commands:

Optional: Add /opt/mssql-tools/bin/ to your PATH environment variable in a bash shell.

To make sqlcmd/bcp accessible from the bash shell for login sessions, modify your PATH in the

/.bash_profile file with the following command:

To make sqlcmd/bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the

/.bashrc file with the following command:

Connect locally

The following steps use sqlcmd to locally connect to your new SQL Server instance.

Run sqlcmd with parameters for your SQL Server name (-S), the user name (-U), and the password (-P). In this tutorial, you are connecting locally, so the server name is localhost . The user name is SA and the password is the one you provided for the SA account during setup.

You can omit the password on the command line to be prompted to enter it.

If you later decide to connect remotely, specify the machine name or IP address for the -S parameter, and make sure port 1433 is open on your firewall.

If successful, you should get to a sqlcmd command prompt: 1> .

If you get a connection failure, first attempt to diagnose the problem from the error message. Then review the connection troubleshooting recommendations.

Create and query data

The following sections walk you through using sqlcmd to create a new database, add data, and run a simple query.

Create a new database

The following steps create a new database named TestDB .

From the sqlcmd command prompt, paste the following Transact-SQL command to create a test database:

On the next line, write a query to return the name of all of the databases on your server:

The previous two commands were not executed immediately. You must type GO on a new line to execute the previous commands:

To learn more about writing Transact-SQL statements and queries, see Tutorial: Writing Transact-SQL Statements.

Insert data

Next create a new table, Inventory , and insert two new rows.

From the sqlcmd command prompt, switch context to the new TestDB database:

Create new table named Inventory :

Insert data into the new table:

Type GO to execute the previous commands:

Select data

Now, run a query to return data from the Inventory table.

From the sqlcmd command prompt, enter a query that returns rows from the Inventory table where the quantity is greater than 152:

Execute the command:

Exit the sqlcmd command prompt

To end your sqlcmd session, type QUIT :

Performance best practices

After installing SQL Server on Linux, review the best practices for configuring Linux and SQL Server to improve performance for production scenarios. For more information, see Performance best practices and configuration guidelines for SQL Server on Linux.

Cross-platform data tools

In addition to sqlcmd, you can use the following cross-platform tools to manage SQL Server:

Tool Description
Azure Data Studio A cross-platform GUI database management utility.
Visual Studio Code A cross-platform GUI code editor that run Transact-SQL statements with the mssql extension.
PowerShell Core A cross-platform automation and configuration tool based on cmdlets.
mssql-cli A cross-platform command-line interface for running Transact-SQL commands.

Connecting from Windows

SQL Server tools on Windows connect to SQL Server instances on Linux in the same way they would connect to any remote SQL Server instance.

If you have a Windows machine that can connect to your Linux machine, try the same steps in this topic from a Windows command-prompt running sqlcmd. Just verify that you use the target Linux machine name or IP address rather than localhost, and make sure that TCP port 1433 is open. If you have any problems connecting from Windows, see connection troubleshooting recommendations.

For other tools that run on Windows but connect to SQL Server on Linux, see:

Other deployment scenarios

For other installation scenarios, see the following resources:

  • Upgrade: Learn how to upgrade an existing installation of SQL Server on Linux
  • Uninstall: Uninstall SQL Server on Linux
  • Unattended install: Learn how to script the installation without prompts
  • Offline install: Learn how to manually download the packages for offline installation

For answers to frequently asked questions, see the SQL Server on Linux FAQ.

Источник

SQL Server в Linux

Применимо к: SQL Server (все поддерживаемые версии) — Linux

Начиная с версии SQL Server 2017 возможна работа SQL Server на Linux. Несмотря на другую операционную систему, это то же ядро СУБД SQL Server с множеством схожих функций и служб.

SQL Server 2019 работает в Linux. Несмотря на другую операционную систему, это то же ядро СУБД SQL Server с множеством схожих функций и служб. Дополнительные сведения об этом выпуске см. в статье Новые возможности SQL Server 2019 для Linux.

Установка

Чтобы начать работу, установите SQL Server на Linux, используя любое из следующих кратких руководств:

Docker поддерживает множество платформ, то есть вы можете запускать образ Docker в Linux, Mac и Windows.

Подключение

После установки подключитесь к экземпляру SQL Server на компьютере с Linux. Вы можете устанавливать подключение как локально, так и удаленно, используя самые разные средства и драйверы. В кратком руководстве показано, как использовать программу командной строки sqlcmd. Также можно использовать следующие средства:

Инструмент Учебник
Visual Studio Code (VS Code) Использование VS Code с SQL Server на Linux
SQL Server Management Studio (SSMS) Использование SSMS в Windows для подключения к SQL Server на Linux
SQL Server Data Tools (SSDT) Использование SSDT с SQL Server на Linux

Изучить

SQL Server 2017 использует одинаковое базовое ядро СУБД на всех поддерживаемых платформах, включая Linux. Благодаря этому многие существующие функции и возможности работают в Linux так же, как и на других платформах. В этой части документации некоторые из этих функций рассматриваются с точки зрения платформы Linux. Кроме того, отмечаются области, в которых платформа Linux предъявляет уникальные требования.

Если вы уже знакомы с SQL Server, изучите общие рекомендации и известные проблемы в заметках об этом выпуске. Также ознакомьтесь с новыми возможностями в SQL Server на Linux и SQL Server 2017 в целом.

SQL Server 2019 (15.x) использует одинаковое базовое ядро СУБД на всех поддерживаемых платформах, включая Linux. Благодаря этому многие существующие функции и возможности работают в Linux так же, как и на других платформах. В этой части документации некоторые из этих функций рассматриваются с точки зрения платформы Linux. Кроме того, отмечаются области, в которых платформа Linux предъявляет уникальные требования.

Если вы уже знакомы с SQL Server на Linux, изучите общие рекомендации и известные проблемы в заметках об этом выпуске. Также ознакомьтесь с новыми возможностями SQL Server 2019 на Linux.

Все версии SQL Server

SQL Server 2017 и SQL Server 2019 (15.x) используют одинаковое базовое ядро СУБД на всех поддерживаемых платформах, включая Linux. Благодаря этому многие существующие функции и возможности работают в Linux так же, как и на других платформах. В этой части документации некоторые из этих функций рассматриваются с точки зрения платформы Linux. Кроме того, отмечаются области, в которых платформа Linux предъявляет уникальные требования.

Если вы уже знакомы с SQL Server на Linux, ознакомьтесь с заметками о выпуске:

Также ознакомьтесь с новыми возможностями:

Ответы на часто задаваемые вопросы об SQL Server на Linux см. в этой статье.

Получение справки

Примите участие в разработке документации по SQL

Знаете ли вы, что содержимое SQL можно изменить самостоятельно? Это не только улучшит нашу документацию, но и даст вам статус участника в создании этой страницы.

Источник

Install sqlcmd and bcp the SQL Server command-line tools on Linux

Applies to: SQL Server (all supported versions) — Linux

The following steps install the command-line tools, Microsoft ODBC drivers, and their dependencies. The mssql-tools package contains:

  • sqlcmd: Command-line query utility.
  • bcp: Bulk import-export utility.

Install the tools for your platform:

This article describes how to install the command-line tools. If you are looking for examples of how to use sqlcmd or bcp, see the links at the end of this topic.

Install tools on RHEL 8

Use the following steps to install the mssql-tools on Red Hat Enterprise Linux.

Enter superuser mode.

Download the Microsoft Red Hat repository configuration file.

Exit superuser mode.

If you had a previous version of mssql-tools installed, remove any older unixODBC packages.

Run the following commands to install mssql-tools with the unixODBC developer package.

To update to the latest version of mssql-tools run the following commands:

Optional: Add /opt/mssql-tools/bin/ to your PATH environment variable in a bash shell.

To make sqlcmd/bcp accessible from the bash shell for login sessions, modify your PATH in the

/.bash_profile file with the following command:

To make sqlcmd/bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the

/.bashrc file with the following command:

Install tools on Ubuntu 16.04

Use the following steps to install the mssql-tools on Ubuntu.

  • Ubuntu 18.04 is supported starting with SQL Server 2019 CU3.
  • Ubuntu 20.04 is supported starting with SQL Server 2019 CU10.
  • If you are using Ubuntu 18.04 or Ubuntu 20.04, change the repository path in step 2 below from /ubuntu/16.04 to /ubuntu/18.04 or /ubuntu/20.04 .

Import the public repository GPG keys.

Register the Microsoft Ubuntu repository.

Update the sources list and run the installation command with the unixODBC developer package.

To update to the latest version of mssql-tools run the following commands:

Optional: Add /opt/mssql-tools/bin/ to your PATH environment variable in a bash shell.

To make sqlcmd/bcp accessible from the bash shell for login sessions, modify your PATH in the

/.bash_profile file with the following command:

To make sqlcmd/bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the

/.bashrc file with the following command:

Install tools on SLES 12

Use the following steps to install the mssql-tools on SUSE Linux Enterprise Server.

Add the Microsoft SQL Server repository to Zypper.

Install mssql-tools with the unixODBC developer package.

To update to the latest version of mssql-tools run the following commands:

Optional: Add /opt/mssql-tools/bin/ to your PATH environment variable in a bash shell.

To make sqlcmd/bcp accessible from the bash shell for login sessions, modify your PATH in the

/.bash_profile file with the following command:

To make sqlcmd/bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the

/.bashrc file with the following command:

Install tools on macOS

A preview of sqlcmd and bcp is now available on macOS. For more information, see the announcement.

Install Homebrew if you don’t have it already:

  • /usr/bin/ruby -e «$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)»

To install the tools for Mac El Capitan and Sierra, use the following commands:

Docker

If you run SQL Server in a Docker container, the SQL Server command-line tools are already included in the SQL Server Linux container image. If you attach to a running container with an interactive bash shell, you can run the tools locally.

Offline installation

If your Linux machine does not have access to the online repositories used in the previous sections, you can download the package files directly. These packages are located in the Microsoft repository, https://packages.microsoft.com.

If you successfully installed with the steps in the previous sections, you do not need to download or manually install the package(s) below. This is only for the offline scenario.

First, locate and copy the mssql-tools package for your Linux distribution:

Linux distribution mssql-tools package location
Red Hat https://packages.microsoft.com/rhel/7.3/prod
SLES https://packages.microsoft.com/sles/12/prod
Ubuntu 16.04 https://packages.microsoft.com/ubuntu/16.04/prod/pool/main/m/mssql-tools

Also locate and copy the msodbcsql package, which is a dependency. The msodbcsql package also has a dependency on either unixODBC-devel (Red Hat and SLES) or unixodbc-dev (Ubuntu). The location of the msodbcsql packages are listed in the following table:

Linux distribution ODBC packages location
Red Hat https://packages.microsoft.com/rhel/8/prod
SLES https://packages.microsoft.com/sles/12/prod
Ubuntu 16.04 msodbcsql
unixodbc-dev

Move the downloaded packages to your Linux machine. If you used a different machine to download the packages, one way to move the packages to your Linux machine is with the scp command.

Install the and packages: Install the mssql-tools and msodbc packages. If you get any dependency errors, ignore them until the next step.

Platform Package install commands
Red Hat sudo yum localinstall msodbcsql- .rpm
sudo yum localinstall mssql-tools- .rpm
SLES sudo zypper install msodbcsql- .rpm
sudo zypper install mssql-tools- .rpm
Ubuntu sudo dpkg -i msodbcsql_ .deb
sudo dpkg -i mssql-tools_ .deb

Resolve missing dependencies: You might have missing dependencies at this point. If not, you can skip this step. In some cases, you must manually locate and install these dependencies.

For RPM packages, you can inspect the required dependencies with the following commands:

For Debian packages, if you have access to approved repositories containing those dependencies, the easiest solution is to use the apt-get command:

This command completes the installation of the SQL Server packages as well.

If this does not work for your Debian package, you can inspect the required dependencies with the following commands:

Next steps

For an example of how to use sqlcmd to connect to SQL Server and create a database, see one of the following quickstarts:

For an example of how to use bcp to bulk import and export data, see Bulk copy data to SQL Server on Linux.

Источник

Читайте также:  Linux для embedded arm
Оцените статью