SQLSERVER也能部署在linux环境?SQLServer2019在CENTOS7部署详解

概述我们知道SQL Server是微软公司推出的重要的数据库产品,通常情况下只支持部署在windows平台上 。不过令人感到兴奋的是,从SQL Server 2017开始支持 linux系统 。此 SQL Server 版本与运行在 Microsoft 操作系统上的 SQL Server 数据库引擎相同,具有许多相似的功能和服务 。下面分享一下centos 7 上安装 Microsoft SQL Server 2019 的步骤 。

SQLSERVER也能部署在linux环境?SQLServer2019在CENTOS7部署详解

文章插图
 
安装过程Step1: 在 CentOS 7 上安装 Microsoft SQL Server 2019
  • 添加SQL Server 2019 镜像仓库
Microsoft SQL Server 2019 可供一般用途使用 。通过在终端上运行以下命令,将存储库添加到 CentOS 7 。
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
  • 更新你的系统缓存
sudo yum makecache# CentOS 7
  • 安装SQL Server 2019
【SQLSERVER也能部署在linux环境?SQLServer2019在CENTOS7部署详解】sudo yum install -y mssql-server要获取有关已安装软件包的信息,请运行:
[root@test ~]# rpm -qi mssql-serverName: mssql-serverVersion: 15.0.4178.1Release: 3Architecture: x86_64Install Date: Fri 29 Oct 2021 02:15:59 PM CSTGroup: UnspecifiedSize: 1213647503License: CommercialSignature: RSA/SHA256, Wed 29 Sep 2021 01:09:50 AM CST, Key ID eb3e94adbe1229cfSource RPM: mssql-server-15.0.4178.1-3.src.rpmBuild Date: Tue 28 Sep 2021 01:50:37 PM CSTBuild Host: hls-build-pipeline-ub2-prod-build-cent73-02Relocations : (not relocatable)Summary: Microsoft SQL Server Relational Database EngineDescription :The mssql-server package contains the Microsoft SQL Server Relational Database Engine.Step 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 – Developer(免费) 。
  1. 接受许可条款
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=0x409The privacy statement can be viewed at:https://go.microsoft.com/fwlink/?LinkId=853010&clcid=0x409Do you accept the license terms? [Yes/No]:Yes
  1. 设置 SQL Server 系统管理员密码
Enter the SQL Server system administrator password: <Password>Confirm the SQL Server system administrator password:<Confirm Password>Configuring SQL Server...sqlservr: This program requires a machine with at least 2000 megabytes of memory./opt/mssql/bin/sqlservr: This program requires a machine with at least 2000 megabytes of memory.Initial setup of Microsoft SQL Server failed. Please consult the ERRORLOGin /var/opt/mssql/log for more information.step3:安装 SQL Server 命令行工具然后使用 unixODBC 开发包安装 mssql-tools 。
sudo curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.reposudo yum -y install mssql-tools unixODBC-develstep 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 端口连接:
sudofirewall-cmd --add-port=1433/tcp --permanentsudofirewall-cmd --reloadStep 4:测试 SQL Server连接到 SQL Server 并验证它是否正常工作 。
$ sqlcmd -S localhost -U SA使用步骤 2 中设置的密码进行身份验证 。
  • 显示数据库用户:
1> select name from sysusers;2> go
  • 创建测试数据库:
# Create newCREATE DATABASE mytestDBSELECT Name from sys.DatabasesGOUSE mytestDBCREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);GOSELECT * FROM Inventory LIMIT 1;


推荐阅读