Run sql on linux

SQL Server on Linux

Starting with SQL Server 2017 (14.x), SQL Server runs on Linux. It’s the same SQL Server database engine, with many similar features and services regardless of your operating system.

SQL Server 2019 is available! To find out what’s new for Linux in the latest release, see What’s new in SQL Server 2019 for Linux.

SQL Server 2019 (15.x) runs on Linux. It’s the same SQL Server database engine, with many similar features and services regardless of your operating system. To find out more about this release, see What’s new in SQL Server 2019 for Linux.

SQL Server 2022 is available! To find out what’s new for Linux in the latest release, see What’s new in SQL Server 2022.

SQL Server 2022 (16.x) runs on Linux. It’s the same SQL Server database engine, with many similar features and services regardless of your operating system. To find out more about this release, see What’s new in SQL Server 2022.

Install

To get started, install SQL Server on Linux using one of the following quickstarts:

Container images

The SQL Server container images are published and available on the Microsoft Container Registry (MCR), and also cataloged at the following locations, based on the operating system image that was used when creating the container image:

  • For RHEL-based SQL Server container images, see SQL Server Red Hat Containers.
  • For Ubuntu-based SQL Server images, see SQL Server on Docker Hub.

Containers will only be published to MCR for the most recent Linux distributions. If you create your own custom SQL Server container image for an older supported distribution, it will still be supported. For more information, see Upcoming updates to SQL Server container images on Microsoft Artifact Registry aka (MCR).

Connect

After installation, connect to the SQL Server instance on your Linux machine. You can connect locally or remotely and with various tools and drivers. The quickstarts demonstrate how to use the sqlcmd command-line tool. Other tools include the following:

Tool Tutorial
Visual Studio Code (VS Code) Use VS Code with SQL Server on Linux
SQL Server Management Studio (SSMS) Use SSMS on Windows to connect to SQL Server on Linux
SQL Server Data Tools (SSDT) Use SSDT with SQL Server on Linux

Explore

Starting with SQL Server 2017 (14.x), SQL Server has the same underlying database engine on all supported platforms, including Linux and containers. Therefore, many existing features and capabilities operate the same way. This area of the documentation exposes some of these features from a Linux perspective. It also calls out areas that have unique requirements on Linux.

If you’re already familiar with SQL Server on Linux, review the release notes for general guidelines and known issues for this release:

Читайте также:  Adding repositories to kali linux

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

Get help

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

Источник

How to Run an SQL File in MySQL (or MariaDB) on Linux/Ubuntu

How to Run a SQL File in MySQL/MariaDB on Linux/Ubuntu

Whether you’re installing a package, following a tutorial, or restoring a backup – it’s useful to be able to execute an SQL script from a file and have it do all of the work for you, rather than having to type it all out.

Most GUI database managers have a simple import option prominently displayed in the menu bar – so here’s how to do it from the command line (and PHPMyAdmin if you’re command-line averse).

From the MySQL Command Line

If you’re logged into the MySQL command line, you can use MySQL statements to execute the contents of a script/file using the source command:

source full/path/to/sql/file.sql
  • You should provide the full absolute path to the file you wish to read as it may not be clear what working directory will be from within MySQL
  • The file will need to be located on the same system on which the MySQL server is running or on a filesystem available to it.
  • The path should not be wrapped in quotes!

From the Shell/Command Line

You can also execute an SQL file without logging into MySQL from the Linux shell – this is especially useful if you wish to make your command part of a Bash/Shell script:

mysql --host="mysql_server" --user="user_name" --database="database_name" --password="user_password" < "path/to/sql/file.sql"

Above, the database login details are provided to the MySQL command, which is then fed commands via standard redirection from the given SQL file. The command directs the contents of the SQL file to the MySQL command.

The path to the SQL file can be relative, and the file should exist on your local computer – it doesn’t have to exist on the remote MySQL server, so it’s perfect for running local SQL scripts on remote servers.

Saving the Output of the SQL Script

If you wish to save the output generated while the script is running rather than just having it output to the screen, you can again use standard redirection to redirect the output into a file:

mysql -u yourusername -p yourpassword yourdatabase < query_file >results_file mysql --host="mysql_server" --user="user_name" --database="database_name" --password="user_password" < "path/to/sql/file.sql" >"path/to/sql/results.txt"

The > command directs the output of the command into the given results file. If the file exists, it is overwritten.

Using phpMyAdmin

If you use phpMyAdmin to administrate your MySQL server, you can also execute MySQL files from there. It’s a good tool for those less comfortable working on the command line.

Navigate to the database you wish to execute the SQL commands within, then go to the import tab and browse for the file you wish to execute.

Press the go button when you’re ready to go. Pretty easy.

Be warned, if you are executing a particularly large file that may take some time to complete, the command line is the best way to go, as phpMyAdmin is limited by the file upload size and is limited in how long it is allowed to execute tasks depending on the configuration of the web server it is running from. If you are having issues uploading a file via phpMyAdmin, then consider checking your php.ini file for an upload limit that might be limiting the file size.

Читайте также:  Radeon vega 3 graphics linux

Источник

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