学习SQL Server从在Linux上安装开始

原创 2016-11-18 衡子 衡子hengzi

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

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

1. 获得YUM源:

下载到本地:

wget https://packages.microsoft.com/config/rhel/7/mssql-server.repo--2016-11-17 18:35:37-- https://packages.microsoft.com/config/rhel/7/mssql-server.repoResolving packages.microsoft.com (packages.microsoft.com)... 13.75.127.55Connecting to packages.microsoft.com (packages.microsoft.com)|13.75.127.55|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 220 [application/octet-stream]
Saving to: 'mssql-server.repo' 100%[=================================================================================================================================>] 220 --.-K/s in 0s2016-11-17 18:35:37 (47.7 MB/s) - 'mssql-server.repo' saved [220/220]

把此文件复制到/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 00:00:00extras | 3.4 kB 00:00:00openlogic | 1.3 kB 00:00:00packages-microsoft-com-mssql-server | 2.9 kB 00:00:00updates | 3.4 kB 00:00:00(1/13): extras/7/x86_64/prestodelta | 78 kB 00:00:00(2/13): openlogic/7/x86_64/filelists | 6.7 kB 00:00:00(3/13): openlogic/7/x86_64/other | 3.7 kB 00:00:00(4/13): extras/7/x86_64/filelists_db | 468 kB 00:00:01(5/13): extras/7/x86_64/other_db | 706 kB 00:00:00(6/13): packages-microsoft-com-mssql-server/filelists_db | 1.4 kB 00:00:00(7/13): packages-microsoft-com-mssql-server/other_db | 728 B 00:00:00(8/13): base/7/x86_64/other_db | 2.3 MB 00:00:01(9/13): updates/7/x86_64/prestodelta | 786 kB 00:00:00(10/13): updates/7/x86_64/filelists_db | 5.3 MB 00:00:01(11/13): base/7/x86_64/filelists_db | 6.2 MB 00:00:03(12/13): updates/7/x86_64/other_db | 79 MB 00:00:04(13/13): packages-microsoft-com-mssql-server/primary_db | 2.4 kB 00:00:06Loading mirror speeds from cached hostfile
openlogic 54/54openlogic 54/54Metadata 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 00:00:00Loading mirror speeds from cached hostfile
Resolving Dependencies--> Running transaction check---> Package mssql-server.x86_64 0:14.0.1.246-6 will be installed--> Finished Dependency Resolution
 
Dependencies Resolved
 ===========================================================================================================================================================================Package Arch Version Repository Size===========================================================================================================================================================================Installing:
mssql-server x86_64 14.0.1.246-6 packages-microsoft-com-mssql-server 138 M
 
Transaction Summary===========================================================================================================================================================================Install 1 Package
 
Total download size: 138 M
Installed size: 138 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/packages-microsoft-com-mssql-server/packages/mssql-server-14.0.1.246-6.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID be1229cf: NOKEY
Public key for mssql-server-14.0.1.246-6.x86_64.rpm is not installed
mssql-server-14.0.1.246-6.x86_64.rpm | 138 MB 00:00:05Retrieving key from https://packages.microsoft.com/keys/microsoft.ascImporting GPG key 0xBE1229CF:
Userid : "Microsoft (Release signing) <gpgsecurity@microsoft.com>"Fingerprint: bc52 8686 b50d 79e3 39d3 721c eb3e 94ad be12 29cf
From : https://packages.microsoft.com/keys/microsoft.ascRunning transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mssql-server-14.0.1.246-6.x86_64 1/1 +-------------------------------------------------------------------+
| Please run /opt/mssql/bin/sqlservr-setup to complete the setup of |
| Microsoft(R) SQL Server(R). |
+-------------------------------------------------------------------+ 
Verifying : mssql-server-14.0.1.246-6.x86_64 1/1 
Installed:
mssql-server.x86_64 0:14.0.1.246-6 
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 foundin /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 3250 megabytes of memory.
Microsoft(R) SQL Server(R) setup failed with error code 1.
Please check the setup log in /var/opt/mssql/log/setup-20161117-184346.logfor 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 foundin /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 2016-11-17 19:52:06 UTC; 37s ago
Main PID: 1539 (sqlservr)
CGroup: /system.slice/mssql-server.service
├─1539 /opt/mssql/bin/sqlservr
└─1547 /opt/mssql/bin/sqlservr
 
Nov 17 19:52:14 hwchefserver sqlservr[1539]: 2016-11-17 19:52:15.06 spid17s SQL Server is now ready for client connections. This is an infor...equired.
Nov 17 19:52:15 hwchefserver sqlservr[1539]: 2016-11-17 19:52:15.13 spid6s Polybase feature disabled.
Nov 17 19:52:15 hwchefserver sqlservr[1539]: 2016-11-17 19:52:15.13 spid6s Clearing tempdb database.
Nov 17 19:52:16 hwchefserver sqlservr[1539]: 2016-11-17 19:52:16.91 spid6s Starting up database 'tempdb'.
Nov 17 19:52:17 hwchefserver sqlservr[1539]: 2016-11-17 19:52:17.58 spid6s The tempdb database has 1 data file(s).
Nov 17 19:52:17 hwchefserver sqlservr[1539]: 2016-11-17 19:52:17.58 spid20s The Service Broker endpoint is in disabled or stopped state.
Nov 17 19:52:17 hwchefserver sqlservr[1539]: 2016-11-17 19:52:17.58 spid20s The Database Mirroring endpoint is in disabled or stopped state.
Nov 17 19:52:17 hwchefserver sqlservr[1539]: 2016-11-17 19:52:17.67 spid20s Service Broker manager has started.
Nov 17 19:52:17 hwchefserver sqlservr[1539]: 2016-11-17 19:52:17.71 spid5s Recovery is complete. This is an informational message only. No ...equired.
Nov 17 19:52:22 hwchefserver sqlservr[1539]: 2016-11-17 19:52: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--2016-11-17 19:59:49-- https://packages.microsoft.com/config/rhel/7/prod.repoResolving packages.microsoft.com (packages.microsoft.com)... 13.75.127.55Connecting to packages.microsoft.com (packages.microsoft.com)|13.75.127.55|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 193 [application/octet-stream]
Saving to: 'prod.repo' 100%[=================================================================================================================>] 193 --.-K/s in 0s
 2016-11-17 19:59:50 (30.2 MB/s) - 'prod.repo' saved [193/193]
 
[root@hwchefserver ~]# mv prod.repo /etc/yum.repos.d/[root@hwchefserver ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00extras | 3.4 kB 00:00:00openlogic | 1.3 kB 00:00:00packages-microsoft-com-mssql-server | 2.9 kB 00:00:00packages-microsoft-com-prod | 2.9 kB 00:00:00updates | 3.4 kB 00:00:00(1/3): packages-microsoft-com-prod/filelists_db | 2.7 kB 00:00:00(2/3): packages-microsoft-com-prod/other_db | 10 kB 00:00:00(3/3): packages-microsoft-com-prod/primary_db | 4.6 kB 00:00:00Loading 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 0:14.0.1.246-1 will be installed--> Processing Dependency: msodbcsql for package: mssql-tools-14.0.1.246-1.x86_64--> Running transaction check---> Package msodbcsql.x86_64 0:13.0.1.0-1 will be installed--> Processing Dependency: unixODBC-utf16 for package: msodbcsql-13.0.1.0-1.x86_64--> Processing Dependency: libodbcinst.so.2()(64bit) for package: msodbcsql-13.0.1.0-1.x86_64--> Running transaction check---> Package unixODBC-utf16.x86_64 0:2.3.1-1 will be installed--> Processing Dependency: libltdl.so.7()(64bit) for package: unixODBC-utf16-2.3.1-1.x86_64--> Running transaction check---> Package libtool-ltdl.x86_64 0:2.4.2-21.el7_2 will be installed--> Finished Dependency Resolution
 
Dependencies Resolved
 ===========================================================================================================================================================Package Arch Version Repository Size===========================================================================================================================================================Installing:
mssql-tools x86_64 14.0.1.246-1 packages-microsoft-com-prod 249 k
Installing for dependencies:
libtool-ltdl x86_64 2.4.2-21.el7_2 updates 49 k
msodbcsql x86_64 13.0.1.0-1 packages-microsoft-com-prod 3.8 M
unixODBC-utf16 x86_64 2.3.1-1 packages-microsoft-com-prod 329 k
 
Transaction Summary===========================================================================================================================================================Install 1 Package (+3 Dependent packages)
 
Total download size: 4.5 M
Installed size: 4.5 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): libtool-ltdl-2.4.2-21.el7_2.x86_64.rpm | 49 kB 00:00:00(2/4): msodbcsql-13.0.1.0-1.x86_64.rpm | 3.8 MB 00:00:00(3/4): mssql-tools-14.0.1.246-1.x86_64.rpm | 249 kB 00:00:00(4/4): unixODBC-utf16-2.3.1-1.x86_64.rpm | 329 kB 00:00:00-----------------------------------------------------------------------------------------------------------------------------------------------------------Total 8.3 MB/s | 4.5 MB 00:00:00Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libtool-ltdl-2.4.2-21.el7_2.x86_64 1/4Installing : unixODBC-utf16-2.3.1-1.x86_64 2/4The 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-1.x86_64 3/4The 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-1.x86_64 4/4Verifying : libtool-ltdl-2.4.2-21.el7_2.x86_64 1/4Verifying : msodbcsql-13.0.1.0-1.x86_64 2/4Verifying : unixODBC-utf16-2.3.1-1.x86_64 3/4Verifying : mssql-tools-14.0.1.246-1.x86_64 4/4 
Installed:
mssql-tools.x86_64 0:14.0.1.246-1 
Dependency Installed:
libtool-ltdl.x86_64 0:2.4.2-21.el7_2 msodbcsql.x86_64 0:13.0.1.0-1 unixODBC-utf16.x86_64 0:2.3.1-1 
Complete!

安装成功!

测试连接:

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

登陆成功。

创建数据库test:

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

查看数据库:

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

创建表hwtable:

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

插入数据:

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

查询:

1> select * from hwtable;2> goid name gender age----------- -------------------- -------------------- -----------1 weiheng male 20 
(1 rows affected)

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

阅读原文

阅读 510

7投诉

sqlserver on linux的更多相关文章

  1. 破解SQLServer for Linux预览版的3.5GB内存限制 (UBUNTU篇)

    在上一篇中我提到了如何破解RHEL上SQLServer的内存大小限制,但是Ubuntu上还有一道检查 这篇我将会讲解如何在3.5GB以下内存的Ubuntu中安装和运行SQLServer for Lin ...

  2. 破解SQLServer for Linux预览版的3.5GB内存限制 (RHEL篇)

    微软发布了SQLServer for Linux,但是安装竟然需要3.5GB内存,这让大部分云主机用户都没办法尝试这个新东西 这篇我将讲解如何破解这个内存限制 要看关键的可以直接跳到第6步,只需要替换 ...

  3. 使用 SQLServer On Linux 作为开发数据库遇到的编码问题

    在维护旧的项目的时候,遇到了使用 varchar 类型存储中文的情况,本地数据库是直接使用来自上古时期的 T-SQL 创建的.为了方便,我就没有安装 Windows 版的 SQLServer,直接用的 ...

  4. 破解SQLServer for Linux预览版的3.5GB内存限制 (RHEL篇) 转

    https://www.ancii.com/database/30842.html 微软发布了SQLServer for Linux,但是安装竟然需要3.5GB内存,这让大部分云主机用户都没办法尝试这 ...

  5. SQLServer for linux安装

    linux下安装sqlserver数据库有2种办法,第一使用yum镜像安装,第二使用rpm安装包安装 rpm安装地址为:https://packages.microsoft.com/rhel/7/ms ...

  6. Sqlserver on linux 高可用集群搭建

    一.环境准备 1 部署环境: 服务器数量:3台 Ip地址:192.168.1.191(主) 192.168.1.192(从) 192.168.1.193(从) 操作系统:CentOS Linux re ...

  7. [官网]SQLSERVER ON linux 的最低要求 以及安装方法

    快速入门:在 Red Hat 上安装 SQL Server 并创建数据库 总体说明: 适用于: SQL Server (仅限 Linux)Azure SQL 数据库Azure SQL 数据仓库并行数据 ...

  8. sqlserver 2017 linux还原windows备份时的路径问题解决

    windows的备份由于路径问题,在Linux上会报错 File 'YourDB_Product' cannot be restored to 'Z:\Microsoft SQL Server\MSS ...

  9. linux Centos下安装 sqlserver

    我使用的是Centos7在虚拟机中完成测试 1.下载设置mssql的yum源,执行以下代码,现在sqlserver的linux版本130多兆,网速慢的请等待 curl https://packages ...

随机推荐

  1. MVC 介绍

    1>.NUGET,发布软件,管理平台: 2>.Razor,mvc视图引擎,集中生成HTML代码模板@开始,有自己的格式,语法,如同web forms视图引擎web forms view e ...

  2. C语言小技巧

    /* 求阶乘时设置最大调用层数,防止栈占满 当从函数进入另一个函数时当前函数的内容会入栈,另一个函数调用完时在出栈 */ int factorial(int n, int level) { //pri ...

  3. UCOS-消息队列(学习笔记)

    消息队列的核心是一个消息的指针数组,UCOS系统初始化时根据OS_CONFI.h中的最大队列个数定义这么多个消息队列(队列的结构)并将他们串联成空的链表,创建消息队列时从空链表中抽出一个并用指针数组的 ...

  4. netty中LengthFieldBasedFrameDecoder的使用

    在org.jboss.netty.handler.codec.frame包中,有LengthFieldBasedFrameDecoder类用来解析带有长度属性的包,只要我们在传输协议中加入包的总长度就 ...

  5. memcached客户端的使用

    一. 概念 Memcached是danga.com(运营LiveJournal的技术团队)开发的一套分布式内存对象缓存系统,用于在动态系统中减少数据库负载,提升性能. 二. 适用场合 1. 分布式应用 ...

  6. Android使用KSOAP2调用WebService及正确导入jar包的问题(转)

    Android使用KSOAP2调用WebService及正确导入jar包的问题(转)     错误信息 最近在学Android使用KSOAP2调用现有的Webservice的方法,期间在网上找了很多代 ...

  7. 移动应用(手机应用)开发IM聊天程序解决方案

    这个解决方法已经定制下来很久了,上一段时间比较忙,没有时间整这些东西.最近稍微好些,不怎么加班.所以抽空总结下,同时也分享给大家,也算是给大家一个借鉴吧!或许这并不是最好的解决方案,但只要能满足当前需 ...

  8. ElasticSearch 概述

    简介 Elasticsearch是一个基于Lucene的开源搜索引擎.Elasticsearch也使用Java开发并使用Lucene作为其核心来实现所有索引和搜索的功能,但是它的目的是通过简单的RES ...

  9. secureCRT如何远程桥接CentOS.

    1.将虚拟机的网络连接方式设置为桥接 2.关闭CentOS的防火墙,这里我是直接从页面上关闭的,没有使用命令 3.设置CentOS的ip为静态地址,不允许自动获取,这样远程连接不需要总修改地址.由于我 ...

  10. asp.net 自定义文本框

    using System;using System.Data;using System.Configuration;using System.Linq;using System.Web;using S ...