微软已经发布了SQL Server on Linux,目前支持Redhat和Ubuntu两种发行版。

下面我们来安装体验一下。

1. 获得YUM源:

YUM的repo文件地址:

https://packages.microsoft.com/config/rhel/7/mssql-server.repo

下载到本地:

wget https://packages.microsoft.com/config/rhel/7/mssql-server.repo
---- ::-- https://packages.microsoft.com/config/rhel/7/mssql-server.repo
Resolving packages.microsoft.com (packages.microsoft.com)... 13.75.127.55
Connecting to packages.microsoft.com (packages.microsoft.com)|13.75.127.55|:... connected.
HTTP request sent, awaiting response... OK
Length: [application/octet-stream]
Saving to: 'mssql-server.repo'
 %[=================================================================================================================================>] --.-K/s in 0s
-- :: (47.7 MB/s) - 'mssql-server.repo' saved [/]

把此文件复制到/etc/yum.repos.d目录:

cp mssql-server.repo /etc/yum.repos.d/

更新yum信息:

[root@hwweb0 ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB ::
extras | 3.4 kB ::
openlogic | 1.3 kB ::
packages-microsoft-com-mssql-server | 2.9 kB ::
updates | 3.4 kB ::
(/): extras//x86_64/prestodelta | kB ::
(/): openlogic//x86_64/filelists | 6.7 kB ::
(/): openlogic//x86_64/other | 3.7 kB ::
(/): extras//x86_64/filelists_db | kB ::
(/): extras//x86_64/other_db | kB ::
(/): packages-microsoft-com-mssql-server/filelists_db | 1.4 kB ::
(/): packages-microsoft-com-mssql-server/other_db | B ::
(/): base//x86_64/other_db | 2.3 MB ::
(/): updates//x86_64/prestodelta | kB ::
(/): updates//x86_64/filelists_db | 5.3 MB ::
(/): base//x86_64/filelists_db | 6.2 MB ::
(/): updates//x86_64/other_db | MB ::
(/): packages-microsoft-com-mssql-server/primary_db | 2.4 kB ::
Loading mirror speeds from cached hostfile
openlogic /
openlogic /
Metadata Cache Created

2. 通过yum安装sql server:

Yum查找mssql的相关信息:

[root@hwweb0 ~]# yum search mssql
Loaded plugins: fastestmirror, langpacks
Repository packages-microsoft-com-mssql-server is listed more than once in the configuration
Loading mirror speeds from cached hostfile
=========================================================================== N/S matched: mssql ============================================================================
mssql-server.x86_64 : Microsoft(R) SQL Server(R) Relational Database Engine
mssql-server-ha.x86_64 : Microsoft(R) SQL Server(R) Relational Database Engine
 
Name and summary matches only, use "search all" for everything.

可以看到有两个版本,ha版本应该是做高可用性的版本。安装mssql-server:

[root@hwweb0 ~]# yum search mssql
Loaded plugins: fastestmirror, langpacks
Repository packages-microsoft-com-mssql-server is listed more than once in the configuration
Loading mirror speeds from cached hostfile
=========================================================================== N/S matched: mssql ============================================================================
mssql-server.x86_64 : Microsoft(R) SQL Server(R) Relational Database Engine
mssql-server-ha.x86_64 : Microsoft(R) SQL Server(R) Relational Database Engine
 
Name and summary matches only, use "search all" for everything.
[root@hwweb0 ~]# yum install mssql-server -y
Loaded plugins: fastestmirror, langpacks
Repository packages-microsoft-com-mssql-server is listed more than once in the configuration
packages-microsoft-com-mssql-server | 2.9 kB ::
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mssql-server.x86_64 :14.0.1.246- will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
===========================================================================================================================================================================
Package Arch Version Repository Size
===========================================================================================================================================================================
Installing:
mssql-server x86_64 14.0.1.246- packages-microsoft-com-mssql-server M
 
Transaction Summary
===========================================================================================================================================================================
Install Package
 
Total download size: M
Installed size: M
Downloading packages:
warning: /var/cache/yum/x86_64//packages-microsoft-com-mssql-server/packages/mssql-server-14.0.1.246-.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID be1229cf: NOKEY
Public key for mssql-server-14.0.1.246-.x86_64.rpm is not installed
mssql-server-14.0.1.246-.x86_64.rpm | MB ::
Retrieving key from https://packages.microsoft.com/keys/microsoft.asc
Importing GPG key 0xBE1229CF:
Userid : "Microsoft (Release signing) <gpgsecurity@microsoft.com>"
Fingerprint: bc52 b50d 79e3 39d3 721c eb3e 94ad be12 29cf
From : https://packages.microsoft.com/keys/microsoft.asc
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mssql-server-14.0.1.246-.x86_64 /
 
+-------------------------------------------------------------------+
| Please run /opt/mssql/bin/sqlservr-setup to complete the setup of |
| Microsoft(R) SQL Server(R). |
+-------------------------------------------------------------------+
 
Verifying : mssql-server-14.0.1.246-.x86_64 /
 
Installed:
mssql-server.x86_64 :14.0.1.246-
 
Complete!

这样就安装好了。

3. 配置sql server

[root@hwweb0 bin]# pwd
/opt/mssql/bin
[root@hwweb0 bin]# ./sqlservr-setup
Microsoft(R) SQL Server(R) Setup
 
You can abort setup at anytime by pressing Ctrl-C. Start this program
with the --help option for information about running it in unattended
mode.
 
The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746388 and found
in /usr/share/doc/mssql-server/LICENSE.TXT.
 
Do you accept the license terms? If so, please type "YES": YES
 
Please enter a password for the system administrator (SA) account:
Please confirm the password for the system administrator (SA) account:
 
Setting system administrator (SA) account password...
sqlservr: This program requires a machine with at least megabytes of memory.
Microsoft(R) SQL Server(R) setup failed with error code .
Please check the setup log in /var/opt/mssql/log/setup--.log
for more information.

我采用的是A1的机器,配置过程提示,内存需要大于3G。把机器升级到A2:

[root@hwchefserver bin]# ./sqlservr-setup
Microsoft(R) SQL Server(R) Setup
 
You can abort setup at anytime by pressing Ctrl-C. Start this program
with the --help option for information about running it in unattended
mode.
 
The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746388 and found
in /usr/share/doc/mssql-server/LICENSE.TXT.
 
Do you accept the license terms? If so, please type "YES": YES
 
Please enter a password for the system administrator (SA) account:
Please confirm the password for the system administrator (SA) account:
 
Setting system administrator (SA) account password...
 
Do you wish to start the SQL Server service now? [y/n]: y
Do you wish to enable SQL Server to start on boot? [y/n]: y
Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server.service to /usr/lib/systemd/system/mssql-server.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server-telemetry.service to /usr/lib/systemd/system/mssql-server-telemetry.service.
 
Setup completed successfully.

配置成功。检查状态:

[root@hwchefserver bin]# systemctl status mssql
● mssql.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
[root@hwchefserver bin]# systemctl status mssql-server
● mssql-server.service - Microsoft(R) SQL Server(R) Database Engine
Loaded: loaded (/usr/lib/systemd/system/mssql-server.service; enabled; vendor preset: disabled)
Active: active (running) since Thu -- :: UTC; 37s ago
Main PID: (sqlservr)
CGroup: /system.slice/mssql-server.service
├─ /opt/mssql/bin/sqlservr
└─ /opt/mssql/bin/sqlservr
 
Nov :: hwchefserver sqlservr[]: -- ::15.06 spid17s SQL Server is now ready for client connections. This is an infor...equired.
Nov :: hwchefserver sqlservr[]: -- ::15.13 spid6s Polybase feature disabled.
Nov :: hwchefserver sqlservr[]: -- ::15.13 spid6s Clearing tempdb database.
Nov :: hwchefserver sqlservr[]: -- ::16.91 spid6s Starting up database 'tempdb'.
Nov :: hwchefserver sqlservr[]: -- ::17.58 spid6s The tempdb database has data file(s).
Nov :: hwchefserver sqlservr[]: -- ::17.58 spid20s The Service Broker endpoint is in disabled or stopped state.
Nov :: hwchefserver sqlservr[]: -- ::17.58 spid20s The Database Mirroring endpoint is in disabled or stopped state.
Nov :: hwchefserver sqlservr[]: -- ::17.67 spid20s Service Broker manager has started.
Nov :: hwchefserver sqlservr[]: -- ::17.71 spid5s Recovery is complete. This is an informational message only. No ...equired.
Nov :: hwchefserver sqlservr[]: -- ::22.59 spid35s The activated proc '[dbo].[sp_syspolicy_events_reader]' running on queue...
Hint: Some lines were ellipsized, use -l to show in full.

SQL Server已经在运行。

3. 检查

安装SQL Tools。SQL Tools:sqlcmd是mssql ODBC的一个工具,可以通过yum的repo直接yum安装。

首先下载yum的repo:

[root@hwchefserver ~]# wget https://packages.microsoft.com/config/rhel/7/prod.repo
---- ::-- https://packages.microsoft.com/config/rhel/7/prod.repo
Resolving packages.microsoft.com (packages.microsoft.com)... 13.75.127.55
Connecting to packages.microsoft.com (packages.microsoft.com)|13.75.127.55|:... connected.
HTTP request sent, awaiting response... OK
Length: [application/octet-stream]
Saving to: 'prod.repo'
 
%[=================================================================================================================>] --.-K/s in 0s
 
-- :: (30.2 MB/s) - 'prod.repo' saved [/]
 
[root@hwchefserver ~]# mv prod.repo /etc/yum.repos.d/
[root@hwchefserver ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB ::
extras | 3.4 kB ::
openlogic | 1.3 kB ::
packages-microsoft-com-mssql-server | 2.9 kB ::
packages-microsoft-com-prod | 2.9 kB ::
updates | 3.4 kB ::
(/): packages-microsoft-com-prod/filelists_db | 2.7 kB ::
(/): packages-microsoft-com-prod/other_db | kB ::
(/): packages-microsoft-com-prod/primary_db | 4.6 kB ::
Loading mirror speeds from cached hostfile
Metadata Cache Created

安装:

[root@hwchefserver ~]# yum install mssql-tools
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mssql-tools.x86_64 :14.0.1.246- will be installed
--> Processing Dependency: msodbcsql for package: mssql-tools-14.0.1.246-.x86_64
--> Running transaction check
---> Package msodbcsql.x86_64 :13.0.1.0- will be installed
--> Processing Dependency: unixODBC-utf16 for package: msodbcsql-13.0.1.0-.x86_64
--> Processing Dependency: libodbcinst.so.()(64bit) for package: msodbcsql-13.0.1.0-.x86_64
--> Running transaction check
---> Package unixODBC-utf16.x86_64 :2.3.- will be installed
--> Processing Dependency: libltdl.so.()(64bit) for package: unixODBC-utf16-2.3.-.x86_64
--> Running transaction check
---> Package libtool-ltdl.x86_64 :2.4.-.el7_2 will be installed
--> Finished Dependency Resolution
 
Dependencies Resolved
 
===========================================================================================================================================================
Package Arch Version Repository Size
===========================================================================================================================================================
Installing:
mssql-tools x86_64 14.0.1.246- packages-microsoft-com-prod k
Installing for dependencies:
libtool-ltdl x86_64 2.4.-.el7_2 updates k
msodbcsql x86_64 13.0.1.0- packages-microsoft-com-prod 3.8 M
unixODBC-utf16 x86_64 2.3.- packages-microsoft-com-prod k
 
Transaction Summary
===========================================================================================================================================================
Install Package (+ Dependent packages)
 
Total download size: 4.5 M
Installed size: 4.5 M
Is this ok [y/d/N]: y
Downloading packages:
(/): libtool-ltdl-2.4.-.el7_2.x86_64.rpm | kB ::
(/): msodbcsql-13.0.1.0-.x86_64.rpm | 3.8 MB ::
(/): mssql-tools-14.0.1.246-.x86_64.rpm | kB ::
(/): unixODBC-utf16-2.3.-.x86_64.rpm | kB ::
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Total 8.3 MB/s | 4.5 MB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libtool-ltdl-2.4.-.el7_2.x86_64 /
Installing : unixODBC-utf16-2.3.-.x86_64 /
The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746838 and found in
/usr/share/doc/msodbcsql/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 : msodbcsql-13.0.1.0-.x86_64 /
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
Installing : mssql-tools-14.0.1.246-.x86_64 /
Verifying : libtool-ltdl-2.4.-.el7_2.x86_64 /
Verifying : msodbcsql-13.0.1.0-.x86_64 /
Verifying : unixODBC-utf16-2.3.-.x86_64 /
Verifying : mssql-tools-14.0.1.246-.x86_64 /
 
Installed:
mssql-tools.x86_64 :14.0.1.246-
 
Dependency Installed:
libtool-ltdl.x86_64 :2.4.-.el7_2 msodbcsql.x86_64 :13.0.1.0- unixODBC-utf16.x86_64 :2.3.-
 
Complete!

安装成功!

测试连接:

[root@hwchefserver ~]# sqlcmd -S localhost -U SA
Password:

登陆成功。

创建数据库test:

> create database test;
> go
> use test;
> go
Changed database context to 'test'.

查看数据库:

> select name from sys.databases;
> go
name
--------------------------------------------------------------------------------------------------------------------------------
master
tempdb
model
msdb
test

创建表hwtable:

> create table hwtable ( id int, name varchar(), gender varchar(), age int);
> go

插入数据:

> insert into hwtable values (, 'weiheng','male',);
> go

查询:

> select * from hwtable;
> go
id name gender age
----------- -------------------- -------------------- -----------
weiheng male
 
( rows affected)

MSSQL Sever On Linux就这样安装完成了!

学习SQL Server从在Linux上安装开始的更多相关文章

  1. SQL Server on Ubuntu——Ubuntu上的SQL Server(全截图)

    本文从零开始一步一步介绍如何在Ubuntu上搭建SQL Server 2017,包括安装系统.安装SQL等相关步骤和方法(仅供测试学习之用,基础篇). 一.   创建Ubuntu系统(Create U ...

  2. 在linux上安装 sql server for linux

    在linux上安装 sql server for linux Install SQL Server on Red Hat Enterprise Linux Install SQL Server To ...

  3. 【BI学习笔记】在Linux上安装Wyn Enterprise商业智能报表服务器

    在百度文库上找来的,放到这里,避免以后丢了. 葡萄城出品的Wyn Enterprise商业智能软件的设计器和查看视图是通过浏览器使用的,不需要安装专门的程序.Wyn Enterprise的服务器端可以 ...

  4. Configure Always On Availability Group for SQL Server on Ubuntu——Ubuntu上配置SQL Server Always On Availability Group

    下面简单介绍一下如何在Ubuntu上一步一步创建一个SQL Server AG(Always On Availability Group),以及配置过程中遇到的坑的填充方法. 目前在Linux上可以搭 ...

  5. 怎样在 Ubuntu Linux 上安装 MySQL

    本教程教你如何在基于 Ubuntu 的 Linux 发行版上安装 MySQL.对于首次使用的用户,你将会学习到如何验证你的安装和第一次怎样去连接 MySQL. -- Sergiu MySQL 是一个典 ...

  6. linux上安装配置samba服务器

    linux上安装配置samba服务器 在linux上安装配置samba服务器 在这给大家介绍一个不错的家伙,samba服务.如果您正在犯愁,如何在Windows和Linux之间实现资源共享,就请看看这 ...

  7. 在Windows和Linux上安装paramiko模块以及easy_install的安装方法

    一.paramiko模块有什么用? paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接.由于使用的是python这样的能够跨平台运行的语言 ...

  8. Sql Server 2008卸载后再次安装一直报错

    sql server 2008卸载之后再次安装一直报错问题. 第一:由于上一次的卸载不干净,可参照百度完全卸载sql server2008 的方式 1. 用WindowsInstaller删除所有与S ...

  9. 在Linux上安装Oracle RAC 12 c(12.1) 虚拟机,一步一步向导

    Oracle RAC 12 c(12.1)在Linux上安装虚拟机,一步一步向导 今天我们将看到如何安装 12 c版本1 RAC(真正的应用程序集群)数据库2 Linux 64位的虚拟机 使用VMWa ...

随机推荐

  1. 1.2CMM/CMMI是什么?

    "CMM是指“能力成熟度模型”,其英文全称为Capability Maturity Model for Software,英文缩写为SW-CMM,简称CMM.它是对于软件组织在定义.实施.度 ...

  2. SpringBoot Maven打包项目JAR/WAR

    安装Maven 1. 登录 http://maven.apache.org/download.cgi 2. 下载 maven 压缩包 3. 解压apache-maven-3.6.0-bin.tar.g ...

  3. JSP JavaBeans

    Javabean的设计原则 公有类 无参公有构造方法 私有属性 getter和setter方法 在Jsp页面中如何使用Javabeans? 像使用普通Java类一样,创建JavaBeans实例. 在J ...

  4. 网络安全-跨站脚本攻击XSS(Cross-Site Scripting)

    一.XSS攻击简介 作为一种HTML注入攻击,XSS攻击的核心思想就是在HTML页面中注入恶意代码,而XSS采用的注入方式是非常巧妙的. 在XSS攻击中,一般有三个角色参与:攻击者.目标服务器.受害者 ...

  5. 通过join方法顺序执行多个线程

    方法一:直接用多线程之间的通讯去解决 package com.toov5.test; import javax.imageio.ImageTypeSpecifier; class Res1{ char ...

  6. android.intent.category.LAUNCHER和android.intent.action.MAIN

    一个应用程序可以有多个Activity,每个Activity是同级别的,那么在启动程序时,最先启动哪个Activity呢? 有些程序可能需要显示在程序列表里,有些不需要.怎么定义呢? android. ...

  7. java基础(4)-数组(1)

    数组:存储同一种数据类型的多个元素的容器数组初始化: 元素类型[] 数组名 = new 元素类型[数组长度]int [] arr = new int[5] 元素类型[] 数组名 = new 元素类型[ ...

  8. R语言学习笔记(2)

    第二章:创建数据集 一 R中的数据 二 数据的输入 一R中的数据 数据集:通常是由数据构成的一个矩形数组,行表示观测,列表示变量 R可以处理的数据类型:数值型.字符型.逻辑型.复数型(虚数).原生型( ...

  9. MYSQL进阶学习笔记一:MySQL编码设定,会话变量和全局变量!(视频序号:进阶_1-3)

    知识点一:MySQL编码设定(1-2) 服务器编码设定: 查看MySQL服务器端的编码格式: SHOW VARIABLES LIKE ‘char%’; 设定编码格式: SET NAMES ‘utf8’ ...

  10. php提前输出响应及注意问题

    1.浏览器和服务器之间是通过HTTP进行通信的,浏览器发送请求给服务器,服务器处理完请求后,发送响应结果给浏览器,浏览器展示给用户.如果服务器处理请求时间比较长,那么浏览器就需要等待服务器的处理结果. ...