如何在Ubuntu上安装MSSQL Server?
#database #ubuntu #mssql

在此博客中,我将演示如何在Ubuntu上安装Microsoft SQL Server。

dmi@dmi-VirtualBox:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.4 LTS
Release: 20.04
Codename: focal
dmi@dmi-VirtualBox:~$
wget -qO https://packages.microsoft.com/keys/microsoft.asc | sudo  apt-key add -
sudo add-apt-repository "$(wget -qO https:// packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"

How to install MSSQL Server on Ubuntu

sudo apt-get update
sudo apt-get install -y mssql-server

How to install MSSQL Server on Ubuntu

sudo /opt/mssql/bin/mssql-conf setup

How to install MSSQL Server on Ubuntu

How to install MSSQL Server on Ubuntu

systemctl status mssql-server --no-pager

How to install MSSQL Server on Ubuntu

让我们安装Microsoft SQL Server命令行工具。

sudo apt-get update
sudo apt install curl
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt-get update
sudo apt-get install mssql-tools unixodbc-dev
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile

relogin

在本地连接到Microsoft SQL Server:

dmi@dmi-VirtualBox:~$ sqlcmd -S localhost -U SA
Password:
1> select @@version
2> go
------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
------------------------------------------------------
------------------------------
Microsoft SQL Server 2019 (RTM-CU15) (KB5008996) -
15.0.4198.2 (X64)
Jan 12 2022 22:30:08
Copyright (C) 2019 Microsoft Corporation
Enterprise Evaluation Edition (64-bit) on
Linux (Ubuntu 20.04.4 LTS) <X64>
(1 rows affected)
1>
Connect to the MS SQL Server remotely:
dmi@dmi-VirtualBox:~$ sqlcmd -S 192.168.0.77 -U SA
Password:
1>
Let’s create some DB and some table:
dmi@dmi-VirtualBox:~$ sqlcmd -S 192.168.0.77 -U SA
Password:
1> create database mydb
2> go
1>
2> select name from sys.databases
3> go
name
------------------------------------------------------
------------------------------------------------------
--------------------
master
tempdb
model
msdb
mydb
(5 rows affected)
1> use mydb
2> go
Changed database context to 'mydb'.
2> create table my_table(id int, name nvarchar(100))
3> go
1>
2>
3> insert into my_table values(1, 'One')
4> go
(1 rows affected)
1> select * from my_table
2> go
id name
-----------
------------------------------------------------------
----------------------------------------------
1 One
(1 rows affected)
1>

How to install MSSQL Server on Ubuntu