SQLServer2017_Install_for_CentOS Linux release 7.5

目录

一:安装 SQL Server

1.1 下载 Microsoft SQL Server 2017 存储库配置文件

1.2 安装 mssql-server

1.3 运行 mssql-conf setup 安装配置

1.4 验证服务是否正在运行

二:安装 SQL Server 命令行工具

2.1 下载 Microsoft Red Hat 存储库配置文件

2.2 删除旧版本的unixODBC 包

2.3 安装新版本mssql-tools 和  unixODBC

2.4 配置环境变量

2.5 本地连接

三:Windows 端SSMS 远程连接测试

四:安装过程成遇到的问题

4.1 服务器内存不足导致安装失败

五:参考文档

 

一:安装 SQL Server

1.1 下载 Microsoft SQL Server 2017 存储库配置文件

操作系统:

CentOS Linux release 7.5.1804 (Core)

[[email protected] yum.repos.d]#

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

 

SQLServer2017_Install_for_CentOS Linux release 7.5                                

[[email protected] yum.repos.d]# pwd

/etc/yum.repos.d

[[email protected] yum.repos.d]# cat mssql-server.repo

[packages-microsoft-com-mssql-server-2017]

name=packages-microsoft-com-mssql-server-2017

baseurl=https://packages.microsoft.com/rhel/7/mssql-server-2017/

enabled=1

gpgcheck=1

gpgkey=https://packages.microsoft.com/keys/microsoft.asc

1.2 安装 mssql-server

[[email protected] yum.repos.d]# yum install mssql-server

……

 

SQLServer2017_Install_for_CentOS Linux release 7.5

 

1.3 运行 mssql-conf setup 安装配置

程序包安装完成后,请运行 mssql-conf setup 命令并按提示设置 SA 密码,然后选择版本。

[[email protected] log]# /opt/mssql/bin/mssql-conf setup

SQLServer2017_Install_for_CentOS Linux release 7.5

SQLServer2017_Install_for_CentOS Linux release 7.5

SQLServer2017_Install_for_CentOS Linux release 7.5

 

 

 

1.4  验证服务是否正在运行

[[email protected] log]# systemctl status mssql-server

SQLServer2017_Install_for_CentOS Linux release 7.5

 

二:安装 SQL Server 命令行工具

若要创建数据库,需要使用一个能够在 SQL Server 上运行 Transact-SQL 语句的工具进行连接。 以下步骤安装 SQL Server 命令行工具: sqlcmd 和bcp 。

2.1 下载 Microsoft Red Hat 存储库配置文件

[[email protected] log]#

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

SQLServer2017_Install_for_CentOS Linux release 7.5

 

2.2 删除旧版本的unixODBC 包

如果你有旧版mssql 工具安装,请删除任何较旧的 unixODBC 包

[[email protected] log]# yum remove unixODBC-utf16 unixODBC-utf16-devel

2.3 安装新版本mssql-tools 和 unixODBC

运行以下命令以安装 mssql-tools 和 unixODBC 开发人员包。

[[email protected] log]# yum install -y mssql-tools unixODBC-devel

……

SQLServer2017_Install_for_CentOS Linux release 7.5

 

2.4 配置环境变量

为方便起见,请将 /opt/mssql-tools/bin/ 添加到 PATH 环境变量。

这样就可以在运行工具时不指定完整路径。 请运行以下命令,以便修改登录会话和交互/ 非登录会话的 PATH :

[[email protected] ~]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile

[[email protected] ~]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc

[[email protected] ~]# source ~/.bashrc

2.5 本地连接

以下步骤使用 sqlcmd 本地连接到新的 SQL Server 实例。

1. 使用 SQL Server 名称 (-S) ,用户名 (-U) 和密码 (-P) 的参数运行 sqlcmd 。

在本教程中,用户进行本地连接,因此服务器名称为 localhost 。

用户名为 SA ,密码是在安装过程中为 SA 帐户提供的密码。

[[email protected] ~]# sqlcmd -S localhost -U SA -P 'Sa123456!'

1> select @@version;

2> Go                                                                                                                   

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Microsoft SQL Server 2017 (RTM-CU13) (KB4466404) - 14.0.3048.4 (X64)

         Nov 30 2018 12:57:58

         Copyright (C) 2017 Microsoft Corporation

         Enterprise Edition: Core-based Licensing (64-bit) on Linux (CentOS Linux 7 (Core))                                                                                 

 

(1 rows affected)

1>      exit

 

三:Windows 端SSMS 远程连接测试

 

  SQLServer2017_Install_for_CentOS Linux release 7.5

select @@version ;

Microsoft SQL Server 2017 (RTM-CU13) (KB4466404) - 14.0.3048.4 (X64)

         Nov 30 2018 12:57:58

         Copyright (C) 2017 Microsoft Corporation

         Enterprise Edition: Core-based Licensing (64-bit) on Linux (CentOS Linux 7 (Core))

 

  SQLServer2017_Install_for_CentOS Linux release 7.5

create database chendb ;

use chendb

create table t1 ( id int );

insert into t1 values (),(),();

select * from t1 ;

select database_id , name , physical_name from sys . master_files ;

SQLServer2017_Install_for_CentOS Linux release 7.5

 

四:安装过程成遇到的问题

4.1 服务器内存不足导致安装失败

[[email protected] mssql]# /opt/mssql/bin/mssql-conf setup

……

sqlservr: This program requires a machine with at least 2000 megabytes of memory.

Microsoft SQL Server 的初始安装失败。请参考错误日志

在 /var/opt/mssql/log 中获取更多信息。

增加服务器内存大于2G ,在重新执行安装;