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

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

Applies to: SQL Server (all supported versions) — 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 the new 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 a number of 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 is 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:

Start SSMS by typing Microsoft SQL Server Management Studio in the Windows search box, and then click the desktop app.

In the Connect to Server window, enter the following information (if SSMS is already running, click Connect > Database Engine to open the Connect to Server window):

Setting Description
Server type The default is database engine; do not 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 setup 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 Authentication

Click Connect.

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

After successfully connecting to your SQL Server, Object Explorer opens and you can now access your database to perform administrative tasks or query data.

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.

In Object Explorer, navigate to the target database on the server. For example, expand System Databases to work with the master database.

Right-click the database and then select New Query.

In the query window, write a Transact-SQL query to select return the names of all databases on your server.

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

Click the Execute button to run the query and see the results.

Although it is possible to do almost any management task with Transact-SQL queries, SSMS is a graphical tool that makes is 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 are 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

Start SSMS and connect to your server in SQL Server on Linux

In Object Explorer, right-click on the Databases folder, and then click *New Database. «

In the New Database dialog, enter a name for your new database, and then click 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

Start SSMS and connect to your server in SQL Server on Linux

In Object Explorer, expand the Databases folder to see a list of all the database on the server.

In Object Explorer, right-click on the database you wish to drop, and then click Delete

In the Delete Object dialog, check Close existing connections and then click 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.

Start SSMS and connect to your server in SQL Server on Linux

In Object Explorer, right-click the server node, and then click 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.

Источник

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.

Источник

Читайте также:  Как сделать китайский windows
Оцените статью