我们知道SQL Server是微软公司推出的重要的数据库产品,通常情况下只支持部署在windows平台上。不过令人感到兴奋的是,从SQL Server 2017开始支持 linux系统。此 SQL Server 版本与运行在 Microsoft 操作系统上的 SQL Server 数据库引擎相同,具有许多相似的功能和服务。下面分享一下centos 7 上安装 Microsoft 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
sudo yum install -y mssql-server
要获取有关已安装软件包的信息,请运行:
[root@test ~]# rpm -qi mssql-server
Name : mssql-server
Version : 15.0.4178.1
Release : 3
Architecture: x86_64
Install Date: Fri 29 Oct 2021 02:15:59 PM CST
Group : Unspecified
Size : 1213647503
License : Commercial
Signature : RSA/SHA256, Wed 29 Sep 2021 01:09:50 AM CST, Key ID eb3e94adbe1229cf
Source RPM : mssql-server-15.0.4178.1-3.src.rpm
Build Date : Tue 28 Sep 2021 01:50:37 PM CST
Build Host : hls-build-pipeline-ub2-prod-build-cent73-02
Relocations : (not relocatable)
Summary : Microsoft SQL Server Relational Database Engine
Description :
The mssql-server package contains the Microsoft SQL Server Relational Database Engine.
软件包安装完成后,运行 mssql-conf setup 并按照提示设置 SA 密码并选择您的版本。
sudo /opt/mssql/bin/mssql-conf setup
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(免费)。
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
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 ERRORLOG
in /var/opt/mssql/log for more information.
然后使用 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
启动 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
连接到 SQL Server 并验证它是否正常工作。
$ sqlcmd -S localhost -U SA
使用步骤 2 中设置的密码进行身份验证。
1> select name from sysusers;
2> go
# 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;
1> select name,database_id from sys.databases;
2> go
1> drop database testDB;
2> go
[root@test ~]# cd /usr/local/src
[root@test src]# wget https://azuredatastudiobuilds.blob.core.windows.NET/releases/1.13.0/azuredatastudio-linux-1.13.0.tar.gz
[root@test src]# tar -xvf ./azuredatastudio-linux-1.13.0.tar.gz -C /usr/local
[root@test src]# cd ../
[root@test local]# echo 'export PATH="$PATH:/usr/local/azuredatastudio-linux-x64"' >> ~/.bashrc
[root@test local]# source ~/.bashrc
# 启动图形化数据库操作界面
[root@test local]# azuredatastudio
# 配置非root用户使用
[root@test local]# exit
[gjp@test local]# echo 'export PATH="$PATH:/usr/local/azuredatastudio-linux-x64"' >> ~/.bashrc
[test@test local]# source ~/.bashrc
# 此处需要安装 libXScrnSaver 依赖 否则会报找不到 libgtk-3.so.0
[root@test local]# yum install libXScrnSaver
# 注意 此处使用的是图形化安装的CentOS7
[test@test local]# azuredatastudio
# windows访问时记得关闭防火墙
[root@test ~]# systemctl stop firewalld
[root@test ~]# systemctl disable firewalld
如果你厌倦了在windows上部署SQLSERVER,也许你可以尝试在linux平台上部署,linux平台上SQLSERVER,能带给你不一样的体验。