溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Ubuntu下如何部署SQL Server 2017

發(fā)布時間:2021-11-16 15:32:13 來源:億速云 閱讀:251 作者:小新 欄目:系統(tǒng)運維

這篇文章將為大家詳細(xì)講解有關(guān)Ubuntu下如何部署SQL Server 2017,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

SQL Server 2017 最近已正式發(fā)布。這是 SQL Server 歷史上***同時發(fā)布 Windows 和 Linux  版。此外,微軟還發(fā)布了能使用 Docker 部署的容器版本。對 SQL Server 而言,這是其歷史上具有里程碑意義的一步,因為這是跨出 Windows  的***個版本,標(biāo)志著 SQL Server 在 Linux 平臺上***可用。

SQL Server 2017 新版本成為***個云端、跨不同操作系統(tǒng)的版本,包括 Linux、Docker。SQL Server 2017 目前支持的  Linux 發(fā)行版包括:Red Hat Enterprise Linux(RHEL), SUSE Linux Enterprise Server 和  Ubuntu。SQL Server 2017 支持 Docker 企業(yè)版,Kubernetes 和 OpenShift 這三大容器平臺。

SQL Server 2017 新特性

  • SQL Server 2017 支持使用 R 和 Python 的分析方法,來做資料庫內(nèi)的機器學(xué)習(xí),意味著不必遷移資料,省下不少時間。

  • 圖數(shù)據(jù)分析功能將使客戶能夠使用圖形數(shù)據(jù)存儲和查詢語言擴展來使用原生的圖形查詢語法,以便在高度互連的數(shù)據(jù)中發(fā)現(xiàn)新的關(guān)系。

  • 自適應(yīng)查詢處理可為數(shù)據(jù)庫帶來更智能的體驗。例如,SQL Server 中的 Adaptive Memory Grants  跟蹤并了解對給定的查詢使用了多少內(nèi)存,以調(diào)整內(nèi)存的使用。

  • Automatic Plan Correction 通過查找和修正性能的回歸來確保持續(xù)的性能。

SQL Server 2017 的核心功能在 Windows 和 Linux 上保持一致,但有少部分依賴于 Windows 功能的特性沒有提供給  Linux (例如集群支持和集成 Windows 身份驗證)。

本文將介紹如何在 Ubuntu 下部署 SQL Server 2017 。

安裝 SQL Server 2017

在 Linux 上 安裝 SQL Server 2017 的先決條件

設(shè)備類型設(shè)備要求
內(nèi)存3.25 GB 及以上
文件系統(tǒng)XFS或EXT4 (其他文件系統(tǒng),如BTRFS,不支持)
磁盤空間6 GB
處理器速度2 GHz
處理器核心2 核
處理器類型僅 x64 兼容

安裝 SQL Server 2017 服務(wù)端

  • 導(dǎo)入公共存儲庫 GPG 密鑰

$ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
  • 增加 Microsoft SQL Server Ubuntu 倉庫

$ add-apt-repository "$(curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list)"
  • 安裝 SQL Server 服務(wù)端

$ apt-get update $ apt-get install -y mssql-server
  • 設(shè)置 SA 密碼,并選擇要安裝的版本

$ /opt/mssql/bin/mssql-conf setup  Choose an edition of SQL Server: 1) Evaluation (free, no production use rights, 180-day limit) 2) Developer (free, no production use rights) 3) Express (free) 4) Web (PAID) 5) Standard (PAID) 6) Enterprise (PAID) 7) Enterprise Core (PAID) 8) I bought a license through a retail sales channel and have a product key to enter.  Details about editions can be found at https://go.microsoft.com/fwlink/?LinkId=852748&clcid=0x409  Use of PAID editions of this software requires separate licensing through a Microsoft Volume Licensing program. By choosing a PAID edition, you are verifying that you have the appropriate number of licenses in place to install and run this software.  Enter your edition(1-8): 1 The license terms for this product can be found in /usr/share/doc/mssql-server or downloaded from: https://go.microsoft.com/fwlink/?LinkId=855864&clcid=0x409  The privacy statement can be viewed at: https://go.microsoft.com/fwlink/?LinkId=853010&clcid=0x409  Do you accept the license terms? [Yes/No]:yes  Enter the SQL Server system administrator password: Confirm the SQL Server system administrator password: Configuring SQL Server...  The licensing PID was successfully processed. The new edition is [Enterprise Evaluation Edition]. Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server.service to /lib/systemd/system/mssql-server.service. Setup has completed successfully. SQL Server is now starting.

一共提供了 8 個版本供選擇,其中自由授予許可版本有:評估、開發(fā)人員和快速。

SA 帳戶必須為強密碼(最少 8 個字符,包括大寫和小寫字母、十進(jìn)制數(shù)字和/或非字母數(shù)字符號)。

  • 驗證服務(wù)是否正在運行

$ systemctl status mssql-server  ● mssql-server.service - Microsoft SQL Server Database Engine Loaded: loaded (/lib/systemd/system/mssql-server.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2017-10-12 11:50:29 CST; 1min 22s ago Docs: https://docs.microsoft.com/en-us/sql/linux Main PID: 20776 (sqlservr) CGroup: /system.slice/mssql-server.service ├─20776 /opt/mssql/bin/sqlservr └─20796 /opt/mssql/bin/sqlservr

安裝 SQL Server 2017 命令行工具

如果要創(chuàng)建數(shù)據(jù)庫,需要使用客戶端工具 sqlcmd 和 bcp。

  • 導(dǎo)入公共存儲庫 GPG 密鑰

$ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
  • 增加 Microsoft Ubuntu 倉庫

$ add-apt-repository "$(curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list)"
  • 安裝 SQL Server 命令行工具 和 unixODBC 開發(fā)人員工具包

$ apt-get update $ apt-get install -y mssql-tools unixodbc-dev

Sqlcmd 工具默認(rèn)安裝到 /opt/mssql-tools/bin/ 中的,為方便使用把 /opt/mssql-tools/bin/  添加到環(huán)境變量中。

$ echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile $ echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc $ source ~/.bashrc

Sqlcmd 是用于連接到 SQL Server 以運行查詢并執(zhí)行管理和開發(fā)的一個命令行工具。如果要使用功能更強大的圖形工具,可使用 SQL Server  Management Studio 或 Visual Studio Code 的 mssql 插件。

  • 使用 Sqlcmd 建立本地連接

Sqlcmd 連接到本地的 SQL Server 實例。密碼是在安裝過程中配置的 SA 帳戶密碼。

$ sqlcmd -S localhost -U SA -P '<YourPassword>'

參數(shù)說明

  • -S 連接 SQL Server 的機器名

  • -U 連接 SQL Server 的用戶名

  • -P 連接 SQL Server 的密碼

連接成功,應(yīng)會顯示 Sqlcmd 命令提示符:1>,就類似下面這樣

$ sqlcmd -S localhost -U SA Password: 1>

創(chuàng)建數(shù)據(jù)庫和查詢數(shù)據(jù)

新建數(shù)據(jù)庫

  • 創(chuàng)建一個名為 TestDB 的新數(shù)據(jù)庫

在 sqlcmd 命令提示符中,執(zhí)行 Transact-SQL 命令以創(chuàng)建測試數(shù)據(jù)庫。

1> CREATE DATABASE TestDB

在 SQL Server 中 命令并沒有立即執(zhí)行, 必須在新行中鍵入 GO 才能執(zhí)行命令。

2> GO
1> SELECT Name from sys.Databases 2> GO Name ---------------------------------------- master tempdb model msdb TestDB  (5 rows affected)

插入數(shù)據(jù)

  • 創(chuàng)建一個新表 Inventory,然后插入兩個新行。

在 sqlcmd 命令提示符中,切換到新的 TestDB 數(shù)據(jù)庫。

1> USE TestDB

創(chuàng)建名為 Inventory 的新表

2> CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)

將數(shù)據(jù)插入新表

3> INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);

批量執(zhí)行上述命令

4> GO

整個執(zhí)行過程如下

1> USE TestDB 2> CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT) 3> INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154); 4> GO Changed database context to 'TestDB'.  (1 rows affected)  (1 rows affected)
  • 查詢數(shù)據(jù)

通過 sqlcmd 命令查詢 Inventory 表中數(shù)量大于 152 的行

1> SELECT * FROM Inventory WHERE quantity > 152; 2> GO id          name         quantity ------ ------------ ----------- 2 orange       154  (1 rows affected)
  • 退出 sqlcmd

要結(jié)束 sqlcmd 會話,請鍵入 QUIT。

1> QUIT

卸載 SQL Server 2017

若要刪除 SQL Server 2017,可使用以下命令

$ apt-get remove mssql-server

刪除包不會刪除生成的數(shù)據(jù)庫文件。 如果你想要刪除的數(shù)據(jù)庫文件,可使用以下命令

$ sudo rm -rf /var/opt/mssql/

***在推薦下微軟良心出品 Visual Studio Code 這個編輯器,功能異常強大、跨平臺并且是開源的。最最最重要的是它比 Atom  快,插件也很豐富。我已從 Atom 轉(zhuǎn)坑入 VSCode了,感謝蝸牛大神的推薦!

下圖為 VSCode+MSSQL 插件的效果圖,有沒有很贊的~

Ubuntu下如何部署SQL Server 2017

Ubuntu下如何部署SQL Server 2017

Ubuntu下如何部署SQL Server 2017

關(guān)于“Ubuntu下如何部署SQL Server 2017”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI