雷达智富

首页 > 内容 > 程序笔记 > 正文

程序笔记

在 CentOS 7/Fedora 上安装 Microsoft SQL Server 2019

2024-06-27 104

从 SQL Server 2017 开始,SQL Server 在 Linux 上运行。此 SQL Server 与在 Microsoft 操作系统上运行的 SQL Server 数据库引擎相同,具有许多相似的功能和服务。

本指南将引导您完成在 CentOS 7 上安装 Microsoft SQL Server 2019 的步骤 | Fedora Linux 系统。截至撰写本文时,SQL Server 2019 可在 Ubuntu/CentOS 和 RHEL Linux 上用于生产。

步骤 1:安装 Microsoft SQL Server 2019

Microsoft SQL Server 2019 可供一般用途使用。通过在终端上运行以下命令将存储库添加到 CentOS 7/Fedora。

sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2019.repo

这会将 SQL Server 2019 存储库下载到 /etc/yum.repos.d/mssql-server.repo

更新系统缓存:

### CentOS 7 ###
sudo yum makecache

### Fedora ###
sudo dnf makecache

然后在 CentOS 7 上安装 SQL Server 2019:

sudo yum install -y mssql-server

对于Fedora,您还可以使用dnf命令;

sudo dnf install -y mssql-server

要获取有关已安装软件包的信息,请运行:

$ rpm -qi mssql-server
Name        : mssql-server
Version     : 15.0.4335.1
Release     : 6
Architecture: x86_64
Install Date: Wed 15 Nov 2023 03:21:33 AM UTC
Group       : Unspecified
Size        : 1178854823
License     : Commercial
Signature   : RSA/SHA256, Tue 26 Sep 2023 05:07:19 AM UTC, Key ID eb3e94adbe1229cf
Source RPM  : mssql-server-15.0.4335.1-6.src.rpm
Build Date  : Tue 26 Sep 2023 04:45:39 AM UTC
Build Host  : fbeb82b6c000000.wmnfyjkxcpjenncm3o2wmpgvnd.phxx.internal.cloudapp.net
Summary     : Microsoft SQL Server Relational Database Engine
...

第 2 步:初始化 MS SQL 数据库引擎

软件包安装完成后,运行mssql-conf setup并按照提示设置 SA 密码并选择您的版本。

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

1. 选择您要使用的版本

Choose an edition of SQL Server:
  1) Evaluation (free, no production use rights, 180-day limit)
  2) Developer (free, no production use rights)
  3) Express (free)
  4) Web (PAID)
  5) Standard (PAID)
  6) Enterprise (PAID)
  7) Enterprise Core (PAID)
  8) I bought a license through a retail sales channel and have a product key to enter.

为我。我会选择2 - 开发人员(免费,无生产使用权)。

Details about editions can be found at
https://go.microsoft.com/fwlink/?LinkId=2109348

Use of PAID editions of this software requires separate licensing through a
Microsoft Volume Licensing program.
By choosing a PAID edition, you are verifying that you have the appropriate
number of licenses in place to install and run this software.

Enter your edition(1-8): 2

2. 接受许可条款

The license terms for this product can be found in
/usr/share/doc/mssql-server or downloaded from:
https://go.microsoft.com/fwlink/?LinkId=855862&;clcid=0x409

The privacy statement can be viewed at:
https://go.microsoft.com/fwlink/?LinkId=853010&;clcid=0x409

Do you accept the license terms? [Yes/No]: Yes

3. 设置 SQL Server 系统管理员密码

Enter the SQL Server system administrator password: <ENTER-STRONG-PASSWORD>
Confirm the SQL Server system administrator password: <Confirm Password>
Configuring SQL Server...

ForceFlush is enabled for this instance.
ForceFlush feature is enabled for log durability.
Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server.service to /usr/lib/systemd/system/mssql-server.service.
Setup has completed successfully. SQL Server is now starting.

步骤 3:安装 SQL Server 命令行工具

然后使用 unixODBC 开发人员包安装 mssql-tools。使用以下命令添加包含所需包的存储库:

sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo

添加存储库后,我们可以继续安装工具

sudo yum -y install mssql-tools unixODBC-devel

安装期间按照指示接受许可条款:

The license terms for this product can be downloaded from
https://aka.ms/odbc17eula and found in
/usr/share/doc/msodbcsql17/LICENSE.txt . By entering 'YES',
you indicate that you accept the license terms.

Do you accept the license terms? (Enter YES or NO)
YES
  Installing : msodbcsql17-17.9.1.1-1.x86_64                                                                                                                                                      2/4
The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746949 and found in
/usr/share/doc/mssql-tools/LICENSE.txt . By entering 'YES',
you indicate that you accept the license terms.

Do you accept the license terms? (Enter YES or NO)
YES

第 4 步:启动并启用 mssql-server 服务

启动 mssql-server 服务

sudo systemctl start mssql-server

使其在系统启动时启动:

sudo systemctl enable mssql-server

/opt/mssql/bin/ 添加到您的 ` PATH 变量中:

echo 'export PATH=$PATH:/opt/mssql/bin:/opt/mssql-tools/bin' | sudo tee /etc/profile.d/mssql.sh

获取文件以开始在当前 shell 会话中使用 MS SQL 可执行二进制文件:

source /etc/profile.d/mssql.sh

如果您有活动的 Firewalld 服务,请允许远程主机连接 SQL Server 端口:

sudo  firewall-cmd --add-port=1433/tcp --permanent
sudo  firewall-cmd --reload

第 4 步:测试 SQL Server

连接到 SQL Server 并验证其是否正常工作。

$ sqlcmd -S localhost -U SA
Password: <INPUT-PASSWORD-SET-IN-STEP-2>

使用步骤 2 中设置的密码进行身份验证。

显示数据库用户:

1> select name from sysusers;
2> go
name
--------------------------------------------------------------------------------------------------------------------------------
##MS_AgentSigningCertificate##
##MS_PolicyEventProcessingLogin##
db_accessadmin
db_backupoperator
db_datareader
db_datawriter
db_ddladmin
db_denydatareader
db_denydatawriter
db_owner
db_securityadmin
dbo
guest
INFORMATION_SCHEMA
public
sys

(16 rows affected)

创建测试数据库:

# Create new
CREATE DATABASE mytestDB
SELECT Name from sys.Databases
GO
USE mytestDB
CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)
INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);
GO
SELECT * FROM Inventory LIMIT 1;

显示 SQL Server 上的数据库。

1> select name,database_id from sys.databases;
2> go

删除数据库:

1> drop database mytestDB;
2> go

对于其他 Linux 发行版,请查看以下指南:

  • 如何在 Ubuntu 上安装 MS SQL
  • 如何在 RHEL/CentOS 8 上安装 Microsoft SQL Server

更新于:4个月前
赞一波!3

文章评论

评论问答