在CentOS 7/Fedora上安装Microsoft SQL Server 2019
SQL Server从SQL Server 2016开始在Linux上运行。此SQL Server是在Microsoft操作系统上运行的相同SQL Server数据库引擎,具有许多相似的功能和服务。
本指南将引导我们完成在CentOS 7上安装Microsoft SQL Server 2019的步骤。 Fedora 32/31/30/29/Linux系统。撰写本文时,SQL Server 2019可在Ubuntu/CentOS和RHEL Linux上用于生产。
在CentOS 7上安装Microsoft SQL Server 2019浅顶Fedora 32/31/29/28
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
更新系统缓存:
sudo yum makecache # CentOS 7 sudo dnf makecache # Fedora
然后安装SQL Server 2019:
sudo yum install -y mssql-server
对于Fedora,运行:
sudo dnf install -y mssql-server
要获取有关已安装软件包的信息,请运行:
$rpm -qi mssql-server Name : mssql-server Version : 15.0.1100.94 Release : 1 Architecture: x86_64 Install Date: Sat 17 Nov 2016 09:12:15 AM UTC Group : Unspecified Size : 1289243002 License : Commercial Signature : RSA/SHA256, Tue 06 Nov 2016 10:12:05 PM UTC, Key ID eb3e94adbe1229cf Source RPM : mssql-server-15.0.1100.94-1.src.rpm Build Date : Tue 06 Nov 2016 08:47:29 AM UTC Build Host : hls-cent3-prod-build-cent73-03 Relocations : (not relocatable) Summary : Microsoft SQL Server Relational Database Engine Description : The mssql-server package contains the Microsoft SQL Server Relational Database Engine.
初始化MS SQL数据库引擎
软件包安装完成后,运行runmssql-conf并按照提示设置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开发人员(免费,没有生产使用权)。
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.SetSQL 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 ERRORLOG in /var/opt/mssql/log for more information.
安装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
启动并启用mssql-server服务
Startmssql服务器服务
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
如果我们有活动的防火墙服务,请允许远程主机的SQL Server端口进行连接:
sudo firewall-cmd --add-port=1433/tcp --permanent sudo firewall-cmd --reload
测试SQL Server
连接到SQL Server并验证其是否正常运行。
$sqlcmd -S localhost -U SA
使用在中设置的密码进行身份验证。
显示数据库用户:
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;
在SQL Server上显示数据库。
1> select name,database_id from sys.databases; 2> go
删除数据库:
1> drop database testDB; 2> go