sqlserver2017 install the Linux version of Guide

Installing SQL Server

  1. Download Microsoft SQL Server 2017 Red Hat repository configuration file:
sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo

prompt

If you want to try SQL Server 2019, you must instead register preview version (2019) repository. For SQL Server 2019 installation, use the following command:

sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-preview.repo
  1. Run the following command to install SQL Server:
sudo yum install -y mssql-server

installing

  1. When the package installation is complete, run the mssql-conf setup command and follow the prompts to set the SA password, and then select the version.
    [Password] ( https://upload-images.jianshu.io/upload_images/8504906-912ea1519f1f4cec.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/606/format/webp

Remark

Be sure to specify a strong password for the SA account (at least eight characters, including uppercase and lowercase letters, decimal numbers and / or non-alphanumeric symbols).

  1. Once configured, verify that the service is running:
systemctl status mssql-server

image.png

  1. To allow remote connections, open SQL Server ports on the firewall on RHEL. The default SQL Server port TCP 1433. If you use FirewallD firewall, you can use the following command:
sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
sudo firewall-cmd --reload

RHEL SQL Server is currently running on your computer, you can use!

Installing SQL Server command-line tool

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

sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
  1. Download Microsoft Red Hat repository configuration file.
sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
  1. If you have a previous version mssql tools installed, please remove any older unixODBC package.
sudo yum remove unixODBC-utf16 unixODBC-utf16-devel
  1. Run the following command to install the mssql-tools and developer unixODBC package.
sudo yum install -y mssql-tools unixODBC-devel

image.png

  1. For convenience, add / opt / mssql-tools / bin / to your PATH environment variable. So that you can not specify a full path when you run the tool. Run the following command to modify PATH login sessions and interactive / non-login session:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc

local connection

The following steps use sqlcmd local connection to the new SQL Server instance.

  1. Using SQL Server name (-S), user name (-U) and password (-P) argument run sqlcmd. In this tutorial, locally connected users, the server name localhost. User name SA, password is the password provided for the SA account during the installation process.
sqlcmd -S localhost -U SA -P '<YourPassword>'
  1. If successful, it should show sqlcmd command prompt: 1>.

prompt

You may omit the password on the command line, in order to receive a password prompt.
If you later decide to connect remotely, specify the -S parameter of the computer name or IP address, and make sure that port 1433 on the firewall is turned on.

If there are mistakes after entering a password
Login Error

View sqlserver state run by command systemctl status mssql-server, the following error
status
online inquiries that, SQL Server does not start, because the operating system does not have 3250MB of memory.

Create and query data

The following sections describe how to use sqlcmd will gradually create a new database, add data and run a simple query.

New Database

The following steps create a named TestDBthe new database.

  1. At the sqlcmd command prompt, paste the following Transact-SQL command to create a test database:
CREATE DATABASE TestDB
  1. On the next line, write a query to return the names of all databases on the server:
SELECT Name from sys.Databases
  1. The first two orders are not executed immediately. You must type in the new GO to execute the previous command line:
GO

Insert data

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

  1. In sqlcmd command prompt, the context switch to the new TestDBdatabase:
USE TestDB
  1. Create a new table named Inventory:
CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)
  1. Insert data into the new table:
INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);
  1. To perform the above-mentioned type GO command:
GO

Select Data

Now, in order to run a query from the Inventoryreturn data table.

  1. Sqlcmd command prompt by entering a query, to return Inventorythe table number of rows is greater than 152:
SELECT * FROM Inventory WHERE quantity > 152;
  1. Excuting an order:
GO

Sqlcmd command prompt exit

To end the sqlcmd session, type QUIT:

QUIT

Guess you like

Origin www.cnblogs.com/smfx1314/p/11130164.html