作了不少年的微軟SQL Server數據庫的管理工做,從SQL Server 6.5一路走來,也離開SQL Server管理轉到開源數據庫MySQL/MariaDB不少年。目前已經將工做平臺轉到Fedora 25,家裏也主要用Fedora 25/MacOS。目前打算在公司內部作一些數據庫方面的知識分享,因爲須要說明一些數據庫方面的基礎,而MySQL對此有着不一樣的支持,因此須要安裝SQL Server,同時也不想運行在VirtualBox虛擬機中,且據說微軟SQL Server已經開始支持Linux。因而搜索了一些資料,開始折騰SQL Server on Fedora 25。php
這裏僅作一些簡要的記錄,理論上說安裝設置過程應該很是順利。linux
第一步:獲取yum源,有兩個源sql
$ sudo wget https://packages.microsoft.com/config/rhel/7/mssql-server.repo -O /etc/yum.repos.d/mssql-server.repo --2017-03-21 10:02:04-- 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: ‘/etc/yum.repos.d/mssql-server.repo’ /etc/yum.repos.d/mssql-server.r 100%[==================================================>] 220 --.-KB/s in 0s 2017-03-21 10:02:04 (22.9 MB/s) - ‘/etc/yum.repos.d/mssql-server.repo’ saved [220/220] $ sudo wget wget https://packages.microsoft.com/config/rhel/7/prod.repo -O /etc/yum.repos.d/prod.repo --2017-03-21 10:03:12-- 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: ‘/etc/yum.repos.d/prod.repo’ /etc/yum.repos.d/prod.repo 100%[======================================================>] 193 --.-KB/s in 0s 2017-03-21 10:03:12 (40.9 MB/s) - ‘/etc/yum.repos.d/prod.repo’ saved [193/193]
第二步:安裝SQL Server和命令行管理工具數據庫
$ sudo dnf search mssql packages-microsoft-com-mssql-server 36 kB/s | 3.8 kB 00:00 packages-microsoft-com-prod 170 kB/s | 18 kB 00:00 ===================================================== N/S Matched: mssql ====================================================== opendbx-mssql.x86_64 : MSSQL backend - provides mssql support in opendbx mssql-tools.x86_64 : Tools for Microsoft(R) SQL Server (R) mssql-server.x86_64 : Microsoft(R) SQL Server(R) Relational Database Engine mssql-server-ha.x86_64 : High Availability support for Microsoft(R) SQL Server(R) Relational Database Engine mssql-server-fts.x86_64 : Microsoft(R) SQL Server(R) Full Text Search mssql-server-agent.x86_64 : Microsoft SQL Server Agent php-ZendFramework-Db-Adapter-Pdo-Mssql.noarch : Zend Framework database adapter for MS SQL PDO $ sudo dnf install mssql-server mssql-tools Last metadata expiration check: 0:00:35 ago on Tue Mar 21 10:03:34 2017. Dependencies resolved. =============================================================================================================================== Package Arch Version Repository Size =============================================================================================================================== Installing: msodbcsql x86_64 13.1.4.0-1 packages-microsoft-com-prod 3.9 M mssql-server x86_64 14.0.405.200-1 packages-microsoft-com-mssql-server 142 M mssql-tools x86_64 14.0.4.0-1 packages-microsoft-com-prod 249 k Transaction Summary =============================================================================================================================== Install 3 Packages Total download size: 146 M Installed size: 146 M Is this ok [y/N]: y Downloading Packages: (1/3): mssql-tools-14.0.4.0-1.x86_64.rpm 95 kB/s | 249 kB 00:02 (2/3): msodbcsql-13.1.4.0-1.x86_64.rpm 42 kB/s | 3.9 MB 01:35 (3/3): mssql-server-14.0.405.200-1.x86_64.rpm 122 kB/s | 142 MB 19:51 ------------------------------------------------------------------------------------------------------------------------------- Total 125 kB/s | 146 MB 19:51 warning: /var/cache/dnf/packages-microsoft-com-mssql-server-6ec86e9fa6acaff2/packages/mssql-server-14.0.405.200-1.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID be1229cf: NOKEY Importing 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.asc Is this ok [y/N]: y Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction The license terms for this product can be downloaded from https://aka.ms/odbc131eula 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.1.4.0-1.x86_64 1/3 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.4.0-1.x86_64 2/3 Installing : mssql-server-14.0.405.200-1.x86_64 3/3 +--------------------------------------------------------------------------+ | Please run sudo /opt/mssql/bin/mssql-conf setup to complete the setup of | | Microsoft(R) SQL Server(R). | +--------------------------------------------------------------------------+ Verifying : mssql-server-14.0.405.200-1.x86_64 1/3 Verifying : mssql-tools-14.0.4.0-1.x86_64 2/3 Verifying : msodbcsql-13.1.4.0-1.x86_64 3/3 Installed: msodbcsql.x86_64 13.1.4.0-1 mssql-server.x86_64 14.0.405.200-1 mssql-tools.x86_64 14.0.4.0-1 Complete!
過程當中若是有包依賴應該能夠自動解決,由於我機器自己安裝有很多開發包,因此本次並無安裝第三方包。bash
同時,正式安裝前會須要導入GPG簽名而且鍵入YES兩次來贊成微軟的許可協議。app
第三步:初始化SQL Server並啓動服務ide
$ cd /opt/mssql/bin/ $ sudo ./mssql-conf setup 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? [Yes/No]:yes Setting up Microsoft SQL Server Enter the new SQL Server system administrator password: Confirm the new SQL Server system administrator password: Starting Microsoft SQL Server... Enabling Microsoft SQL Server to run at boot... Created symlink /etc/systemd/system/multi-user.target.wants/mssql-server.service → /usr/lib/systemd/system/mssql-server.service. Setup completed successfully.
使用命令行初始化嚮導,僅需贊成許可協議及提供sa的密碼便可。初始化完成後服務自動啓動。工具
查看服務運行狀態this
$ systemctl status mssql-server ● mssql-server.service - Microsoft SQL Server Database Engine Loaded: loaded (/usr/lib/systemd/system/mssql-server.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2017-03-21 10:35:54 CST; 11min ago Docs: https://docs.microsoft.com/en-us/sql/linux Main PID: 17354 (sqlservr) Tasks: 154 CGroup: /system.slice/mssql-server.service ├─17354 /opt/mssql/bin/sqlservr └─17420 /opt/mssql/bin/sqlservr Mar 21 10:36:00 rx-wj39106 sqlservr[17354]: [66B blob data] Mar 21 10:36:00 rx-wj39106 sqlservr[17354]: [75B blob data] Mar 21 10:36:00 rx-wj39106 sqlservr[17354]: [96B blob data] Mar 21 10:36:00 rx-wj39106 sqlservr[17354]: [100B blob data] Mar 21 10:36:00 rx-wj39106 sqlservr[17354]: [71B blob data] Mar 21 10:36:00 rx-wj39106 sqlservr[17354]: [124B blob data] Mar 21 10:41:01 rx-wj39106 sqlservr[17354]: [71B blob data] Mar 21 10:43:03 rx-wj39106 sqlservr[17354]: [66B blob data] Mar 21 10:43:03 rx-wj39106 sqlservr[17354]: [109B blob data] Mar 21 10:43:03 rx-wj39106 sqlservr[17354]: [110B blob data]
查看本地端口,發現1433/1434已經在監聽當中了命令行
$ ss -nat State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 5 127.0.0.1:631 *:* LISTEN 0 128 *:1433 *:* LISTEN 0 128 127.0.0.1:1434 *:* LISTEN 0 128 *:8000 *:* LISTEN 0 128 *:8800 *:* LISTEN 0 128 127.0.0.1:9000 *:* LISTEN 0 80 *:3306 *:* LISTEN 0 128 *:3307 *:* LISTEN 0 128 *:111 *:* LISTEN 0 128 *:80 *:*
第四步:鏈接SQL Server
$ cd /opt/mssql-tools/bin/ $ ./sqlcmd -S localhost -U sa Password: 1> CREATE DATABASE sbtest; 2> GO 1> USE sbtest; 2> GO Changed database context to 'sbtest'. 1> CREATE TABLE sbtest1 (id INT NOT NULL PRIMARY KEY, cdate DATETIME NOT NULL DEFAULT GETDATE()); 2> GO 1> INSERT INTO sbtest1 (id) VALUES (1); 2> INSERT INTO sbtest1 (id) VALUES (2); 3> INSERT INTO sbtest1 (id) VALUES (3); 4> INSERT INTO sbtest1 (id) VALUES (4); 5> INSERT INTO sbtest1 (id) VALUES (5); 6> GO (1 rows affected) (1 rows affected) (1 rows affected) (1 rows affected) (1 rows affected) 1> SELECT id,cdate FROM sbtest1; 2> GO id cdate ----------- ----------------------- 1 2017-03-21 10:44:44.010 2 2017-03-21 10:44:44.010 3 2017-03-21 10:44:44.010 4 2017-03-21 10:44:44.010 5 2017-03-21 10:44:44.010 (5 rows affected)
鏈接SQL Server,建立數據庫sbtest,建立表sbtest1,添加/查詢數據,一切跟預期一致,至此SQL Server在Fedora 25上安裝成功。