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

微软已经发布了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
--2016-11-17 18:35:37-- 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|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 220 [application/octet-stream]
Saving to: ‘mssql-server.repo‘
 100%[=================================================================================================================================>] 220 --.-K/s in 0s
2016-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信息:

[[email protected] ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
openlogic | 1.3 kB 00:00:00
packages-microsoft-com-mssql-server | 2.9 kB 00:00:00
updates | 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:06
Loading mirror speeds from cached hostfile
openlogic 54/54
openlogic 54/54
Metadata Cache Created

2. 通过yum安装sql server:

Yum查找mssql的相关信息:

[[email protected] ~]# 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:

[[email protected] ~]# 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.
[[email protected] ~]# 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:00
Loading 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:05
Retrieving key from https://packages.microsoft.com/keys/microsoft.asc
Importing GPG key 0xBE1229CF:
Userid : "Microsoft (Release signing) <[email protected]>"
Fingerprint: bc52 8686 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-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

[[email protected] bin]# pwd
/opt/mssql/bin
[[email protected] 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 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.log
for more information.

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

[[email protected] 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.

配置成功。检查状态:

[[email protected] bin]# systemctl status mssql
● mssql.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
[[email protected] 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:

[[email protected] ~]# wget https://packages.microsoft.com/config/rhel/7/prod.repo
--2016-11-17 19:59:49-- 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|: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]
 
[[email protected] ~]# mv prod.repo /etc/yum.repos.d/
[[email protected] ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
openlogic | 1.3 kB 00:00:00
packages-microsoft-com-mssql-server | 2.9 kB 00:00:00
packages-microsoft-com-prod | 2.9 kB 00:00:00
updates | 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:00
Loading mirror speeds from cached hostfile
Metadata Cache Created

安装:

[[email protected] ~]# 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:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libtool-ltdl-2.4.2-21.el7_2.x86_64 1/4
Installing : unixODBC-utf16-2.3.1-1.x86_64 2/4
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-1.x86_64 3/4
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-1.x86_64 4/4
Verifying : libtool-ltdl-2.4.2-21.el7_2.x86_64 1/4
Verifying : msodbcsql-13.0.1.0-1.x86_64 2/4
Verifying : unixODBC-utf16-2.3.1-1.x86_64 3/4
Verifying : 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!

安装成功!

测试连接:

[[email protected] ~]# sqlcmd -S localhost -U SA
Password:

登陆成功。

创建数据库test:

1> create database test;
2> go
1> 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> go
id name gender age
----------- -------------------- -------------------- -----------
1 weiheng male 20
 
(1 rows affected)

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

时间: 2024-10-09 20:21:20

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

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

本文从零开始一步一步介绍如何在Ubuntu上搭建SQL Server 2017,包括安装系统.安装SQL等相关步骤和方法(仅供测试学习之用,基础篇). 一.   创建Ubuntu系统(Create Ubuntu System) 1.      前提准备 由于本文主要研究SQL Server 2017在Linux上的搭建方法,从Install SQL Server on Linux中得知当前SQL Server 2017 CTP 2.0对于Ubuntu系统支持16.04和16.10,同时可以直接下

linux上安装nodejs(想在linux上学习nodejs的可以来看看)

说明: 使用CentOS系统,进行nodejs安装,nodejs版本-v0.8.7. 1,先下载nodejs: # wget http://nodejs.org/dist/v0.8.7/node-v0.8.7.tar.gz 2,解压文件 # tar xvf node-v0.8.7.tar.gz 3,进入解压目录 # cd node-v0.8.7 4,检查所需要配置 # ./configure 出现错误提示: Exception: Call to '(echo | $(echo ${CXX_hos

怎样在 Ubuntu Linux 上安装 MySQL

本教程教你如何在基于 Ubuntu 的 Linux 发行版上安装 MySQL.对于首次使用的用户,你将会学习到如何验证你的安装和第一次怎样去连接 MySQL. -- Sergiu MySQL 是一个典型的数据库管理系统.它被用于许多技术栈中,包括流行的 LAMP (Linux.Apache.MySQL.PHP)技术栈.它已经被证实了其稳定性.另一个让 MySQL 受欢迎的原因是它是开源的. MySQL 是关系型数据库(基本上是表格数据).以这种方式它很容易去存储.组织和访问数据.它使用SQL(结

VM虚拟机下在LINUX上安装ORACLE 11G单实例数据库

VM虚拟机下在LINUX上安装ORACLE 11G单实例数据库 1.环境及安装前规划:虚拟机及OS如下 环境:VMware Wordstation ACE版 6.0.2 操作系统:OracleLinux-R5-U8-Server-i386-dvd    3.2G 安装操作系统,这里需要注意的是磁盘空间要预留足够. 我的规划是: 虚拟机分配1024M内存,当然如果主机内存足够,安装时内存设置2048M可以更快. 虚拟机分配一块磁盘,30G磁盘空间. /boot 100M ext3 /    20G

Oracle菜鸟学习之在RedHat 6.5上安装Oracle

Oracle菜鸟学习之在RedHat 6.5上安装Oracle 11G 首发:http://www.arppinging.com/wordpress/?p=90 安装前准备工作 上传数据库软件至/tmp/下,并修改文件权限 chmod -R 755 /tmp/database/ 创建用户和组 创建oracle用户,并将oracle用户加入oinstall和dba组,后面安装的时候需要用到 [[email protected] ~]# groupadd oinstall [[email prote

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

Oracle RAC 12 c(12.1)在Linux上安装虚拟机,一步一步向导 今天我们将看到如何安装 12 c版本1 RAC(真正的应用程序集群)数据库2 Linux 64位的虚拟机 使用VMWare或Oracle VirtualBox. 甲骨文的“c”12 c代表“ 云 ” 有一些重要和有趣的变化时安装12 c相比11 g RAC. 甲骨文似乎增加了很多新的有趣的特性在12摄氏度. 请注意,我们需要2虚拟机各有3 GB内存. 所以如果你有足够的记忆你的笔记本电脑/ PC机或服务器上,那么你

Linux 上安装 weblogic12C (静默安装) (一)

最近负责在linux上安装weblogic,领导说要安装最新的版本,版本号为 12.1.X.开始以为和旧版安装一样,使用控制台的方式,下载bin文件,然后一步步在console执行下来就行了.万万没想到,从12C版本后, bin文件不提供了,改成全系统通用的jar文件 (generic.jar).试了半天原来那种安装方式不能用了,非得用图形界面安装.由于服务器是在其他地方,肯定不能跑到主机的地址那边.于是各种google.各种找材料, 最后终于找到一种静默方式的安装.大家看下文. PS:经过公司

Linux上安装MySQL5.6

OS & MySQL的版本和配置: MySQL Version: 5.6.19 Linux Version: Linux boston.oracle.com 2.6.18-164.el5 #1 SMP Thu Sep 3 02:16:47 EDT 2009 i686 i686 i386 GNU/Linux 一,下载MySQL安装软件,请到www.oracle.com   去找DATABASE DOWNLOAD,下载MySQL需要注册一个账号.我下载的版本如下: 下载后解压就是以下的8个文件 :

在 Ubuntu Server 16.04 LTS 上安装 LAMP

在 Ubuntu Server 16.04 LTS 上安装 LAMP LAMP 方案是一系列自由和开源软件的集合,包含了 Linux.Web 服务器 (Apache). 数据库服务器 (MySQL / MariaDB) 和 PHP (脚本语言). LAMP 是那些需要安装和构建动态网页应用的基础平台,比如WordPress.Joomla.OpenCart 和 Drupal,我将描述如何在 Ubuntu Server 16.04 LTS 上安装 LAMP,众所周知 Ubuntu 是一个基于 Lin