Sql server linux tools

Install the SQL Server command-line tools sqlcmd and bcp on 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 Next steps at the end of this article.

sqlcmd and bcp are available in mssql-tools18 for x64 and arm64 architectures. For a modern alternative across Linux, macOS, and Windows, see go-sqlcmd utility.

Install tools on Linux

These instructions are for installing the Microsoft ODBC 18 packages. For previous versions, see Install the Microsoft ODBC driver for SQL Server (Linux).

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

curl https://packages.microsoft.com/config/rhel/8/prod.repo > /etc/yum.repos.d/mssql-release.repo 
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo 
sudo yum remove mssql-tools unixODBC-utf16 unixODBC-utf16-devel 
sudo yum install -y mssql-tools18 unixodbc-dev 
sudo yum check-update sudo yum update mssql-tools18 
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bash_profile 

To make sqlcmd and bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the ~/.bashrc file with the following command:

echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc source ~/.bashrc 

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

curl -O https://packages.microsoft.com/keys/microsoft.asc rpm --import microsoft.asc 
zypper ar https://packages.microsoft.com/config/sles/15/prod.repo 
zypper ar https://packages.microsoft.com/config/sles/12/prod.repo 
sudo zypper install -y mssql-tools18 unixodbc-dev 
sudo zypper refresh sudo zypper update mssql-tools18 
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bash_profile 

To make sqlcmd or bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the ~/.bashrc file with the following command:

echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc source ~/.bashrc 

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

  • Ubuntu 18.04 is supported starting with SQL Server 2019 (15.x) CU 3.
  • Ubuntu 20.04 is supported starting with SQL Server 2019 (15.x) CU 10.
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list 
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list 
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list 
sudo apt-get update sudo apt-get install mssql-tools18 unixodbc-dev 
sudo apt-get update sudo apt-get install mssql-tools18 
echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bash_profile 

To make sqlcmd and bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the ~/.bashrc file with the following command:

echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc source ~/.bashrc 

Install tools on macOS

Install Homebrew if you don’t have it already:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 

To install the tools for macOS El Capitan and later versions, use the following commands:

# brew untap microsoft/mssql-preview if you installed the preview version brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release brew update brew install mssql-tools18 

Install tools on 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.

Читайте также:  Как сменить пароль в линукс убунту

If you are creating a container with the SQL Server command-line tools, you should add ACCEPT_EULA=Y to the installation command to silently accept the EULA, and not interrupt image creation. An example final command as part of installation on an Ubuntu-based image is:

sudo ACCEPT_EULA=Y apt-get install mssql-tools18 unixodbc-dev 

Offline installation

If your Linux machine doesn’t 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 following package(s). This is only for the offline scenario.

sudo yum localinstall msodbcsql18-.rpm sudo yum localinstall mssql-tools18-.rpm 
rpm -qpR msodbcsql18-.rpm rpm -qpR mssql-tools18-.rpm 
sudo zypper install msodbcsql18-.rpm sudo zypper install mssql-tools18-.rpm 
rpm -qpR msodbcsql18-.rpm rpm -qpR mssql-tools18-.rpm 
sudo dpkg -i msodbcsql18_.deb sudo dpkg -i mssql-tools18_.deb 

If this doesn’t work for your Debian package, you can inspect the required dependencies with the following commands:

dpkg -I msodbcsql18__amd64.deb | grep "Depends:" dpkg -I mssql-tools18__amd64.deb | grep "Depends:" 

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.

Contribute to SQL documentation

Did you know that you can edit SQL content yourself? If you do so, not only do you help improve our documentation, but you also get credited as a contributor to the page.

Feedback

Submit and view feedback for

Источник

Use SQL Server Management Studio on Windows to manage SQL Server on Linux

This article introduces SQL Server Management Studio (SSMS) and walks you through a couple of common tasks. SSMS is a Windows application, so use SSMS when you have a Windows machine that can connect to a remote SQL Server instance on Linux.

If you do not have a Windows machine to run SSMS on, consider using Azure Data Studio. It provides a graphical tool for managing SQL Server and runs on both Linux and Windows.

SQL Server Management Studio (SSMS) is part of a suite of SQL tools that Microsoft offers free of charge for your development and management needs. SSMS is an integrated environment to access, configure, manage, administer, and develop all components of SQL Server. It can connect to SQL Server running on any platform both on-premises, in Docker containers, and in the cloud. It also connects to Azure SQL Database and Azure Synapse Analytics. SSMS combines a broad group of graphical tools with many rich script editors to provide access to SQL Server to developers and administrators of all skill levels.

Читайте также:  Установка вайн линукс минт

SSMS offers a broad set of development and management capabilities for SQL Server, including tools to:

  • Configure, monitor, and administer single or multiple instances of SQL Server
  • Deploy, monitor, and upgrade data-tier components such as databases and data warehouses
  • Backup and restore databases
  • Build and execute T-SQL queries and scripts and see results
  • Generate T-SQL scripts for database objects
  • View and edit data in databases
  • Visually design T-SQL queries and database objects such as views, tables, and stored procedures

See What is SSMS? for more information on SSMS.

Install the newest version of SQL Server Management Studio (SSMS)

When working with SQL Server, you should always use the most recent version of SQL Server Management Studio (SSMS). The latest version of SSMS is continually updated and optimized and currently works with SQL Server on Linux. To download and install the latest version, see Download SQL Server Management Studio. To stay up-to-date, the latest version of SSMS prompts you when there’s a new version available to download.

Before using SSMS to manage Linux, review the known issues for SSMS on Linux.

Connect to SQL Server on Linux

Use the following basic steps to get connected:

  1. Start SSMS by typing Microsoft SQL Server Management Studio in the Windows search box, and then select the desktop app. SQL Server Management Studio
  2. In the Connect to Server window, enter the following information (if SSMS is already running, select Connect > Database Engine to open the Connect to Server window):
    Setting Description
    Server type The default is database engine; don’t change this value.
    Server name Enter the name of the target Linux SQL Server machine, or its IP address and port in the format IP,port .
    Authentication For SQL Server on Linux, use the authentication method that is set up for your environment. SQL Server Authentication is set up by default.
    Login 1 Enter the name of a user with access to a database on the server (for example, the default SA account created during setup).
    Password 1 Enter the password for the specified user (for the SA account, you created this during setup).

    1 Login and Password only available with SQL Server AuthenticationSQL Server Management Studio: Connect to SQL Database server

  3. Select Connect.

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

Run Transact-SQL queries

After you connect to your server, you can connect to a database and run Transact-SQL queries. Transact-SQL queries can be used for almost any database task.

  1. In Object Explorer, navigate to the target database on the server. For example, expand System Databases to work with the master database.
  2. Right-click the database and then select New Query.
  3. In the query window, write a Transact-SQL query to select return the names of all databases on your server.
SELECT [Name] FROM sys.Databases 

Success. Connect to SQL Database server: SQL Server Management Studio

If you’re new to writing queries, see Writing Transact-SQL Statements.

  • Select the Execute button to run the query and see the results.
  • Although it’s possible to do almost any management task with Transact-SQL queries, SSMS is a graphical tool that makes it easier to manage SQL Server. The following sections provide some examples of using the graphical user interface.

    Create and manage databases

    While connected to the master database, you can create databases on the server and modify or drop existing databases. The following steps describe how to accomplish several common database management tasks through Management Studio. To perform these tasks, make sure you’re connected to the master database with the server-level principal login that you created when you set up SQL Server on Linux.

    Create a new database

    1. Start SSMS and connect to your server in SQL Server on Linux.
    2. In Object Explorer, right-click on the Databases folder, and then select New Database. .
    3. In the New Database dialog, enter a name for your new database, and then select OK.

    The new database is successfully created in your server. If you prefer to create a new database using T-SQL, then see CREATE DATABASE (SQL Server Transact-SQL).

    Drop a database

    1. Start SSMS and connect to your server in SQL Server on Linux.
    2. In Object Explorer, expand the Databases folder to see a list of all the database on the server.
    3. In Object Explorer, right-click on the database you wish to drop, and then select Delete.
    4. In the Delete Object dialog, check Close existing connections and then select OK.

    The database is successfully dropped from your server. If you prefer to drop a database using T-SQL, then see DROP DATABASE (SQL Server Transact-SQL).

    Use Activity Monitor to see information about SQL Server activity

    The Activity Monitor tool is built into SQL Server Management Studio (SSMS) and displays information about SQL Server processes and how these processes affect the current instance of SQL Server.

    1. Start SSMS and connect to your server in SQL Server on Linux.
    2. In Object Explorer, right-click the server node, and then select Activity Monitor.

    Activity Monitor shows expandable and collapsible panes with the following information:

    • Overview
    • Processes
    • Resource Waits
    • Data File I/O
    • Recent Expensive Queries
    • Active Expensive Queries

    When a pane is expanded, Activity Monitor queries the instance for information. When a pane is collapsed, all querying activity stops for that pane. You can expand one or more panes at the same time to view different kinds of activity on the instance.

    Next steps

    Contribute to SQL documentation

    Did you know that you can edit SQL content yourself? If you do so, not only do you help improve our documentation, but you also get credited as a contributor to the page.

    Источник

    Оцените статью
    Adblock
    detector