Centos 7.5 安裝Sql Server 2017

1、下載 Microsoft SQL Server 2017 Red Hat 存儲庫配置文件:

curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo

2、運行以下命令以安裝 SQL Server:下載mssql-server.xxxx.rpm源的時候比較慢,耐心等待(親測VMware中下載需要1-3個小時不等,服務器下載半個小時,祝你們好運)

yum install -y mssql-server

3、包安裝完成後,運行 mssql-conf setup,按照提示設置 SA 密碼並選擇版本。

# 以下 SQL Server 2017 版本是免費提供許可的:Evaluation、Developer 和 Express 版。

/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): 2
# 輸入 2 即可、Developer 爲開發版本、免費

The license terms for this product can be found in
/usr/share/doc/mssql-server or downloaded from:
https://go.microsoft.com/fwlink/?LinkId=855862&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]: y

# 你接受授權條款嗎?(是/否): 輸入 y 即可

Enter the SQL Server system administrator password: 1234ABCDabcd

# 然後就是輸入密碼,請確保爲 SA 帳戶指定強密碼(最少 8 個字符,包括大寫和小寫字母、十進制數字和/或非字母數字符號)。

4、完成配置後,驗證服務是否正在運行:

systemctl status mssql-server

# Active: active (running) 表示活躍/啓動成功

5、若要允許遠程連接,請在 RHEL 的防火牆上打開 SQL Server 端口。 默認的 SQL Server 端口爲 TCP 1433。 如果爲防火牆使用的是 FirewallD,則可以使用以下命令:Centos 7.X 防火牆安裝

# 添加防火牆規則
firewall-cmd --zone=public --add-port=1433/tcp --permanent

# 重新加載規則並重啓服務
firewall-cmd --complete-reload

安裝 SQL Server 命令行工具

若要創建數據庫,則需要使用可在 SQL Server 上運行 Transact-SQL 語句的工具進行連接。 以下步驟將安裝 SQL Server 命令行工具:

1、下載 Microsoft Red Hat 存儲庫配置文件。

curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo

2、如果安裝了早期版本的 mssql-tools,請刪除所有舊的 unixODBC 包。

yum remove unixODBC-utf16 unixODBC-utf16-devel

3、運行以下命令,以使用 unixODBC 開發人員包安裝 mssql-tools

yum install -y mssql-tools unixODBC-devel


# you indicate that you accept the license terms.

# Do you accept the license terms? (Enter YES or NO)

# 輸入 yes 即可

4、爲方便起見,向 PATH 環境變量添加 /opt/mssql-tools/bin/ 。 這樣可以在不指定完整路徑的情況下運行這些工具。 運行以下命令以修改登錄會話和交互式/非登錄會話的路徑 :

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

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

source ~/.bashrc

# 以上爲三條命令分別執行

本地連接

以下步驟使用 sqlcmd 本地連接到新的 SQL Server 實例

1、使用 SQL Server 名稱 (-S),用戶名 (-U) 和密碼 (-P) 的參數運行 sqlcmd 。 在本教程中,用戶進行本地連接,因此服務器名稱爲 localhost。 用戶名爲 SA,密碼是在安裝過程中爲 SA 帳戶提供的密碼。

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

# sqlcmd -S localhost -U SA -P '1234ABCDabcd'

2、如果成功,應會顯示 sqlcmd 命令提示符:1>

[root@localhost ~]# sqlcmd -S localhost -U SA -P '1234ABCDabcd'
1> create database demo
2> go
1> select name from sys.Databases
2> go
Name                                                                                                                            
--------------------------------------------------------------------------------------------------------------------------------
master                                                                                                                          
tempdb                                                                                                                          
model                                                                                                                           
msdb                                                                                                                            
demo                                                                                                                            

(5 rows affected)
1> quit

# 說明我剛剛創建的demo數據庫成功了; 輸入 quit 回車退出, exit 同樣也可以退出

遠程連接

以下步驟遠程連接Sql Server

1、如果是服務器,那麼就用服務器的外網IP,我這裏是VMware中的Centos 7,所以我需要用查看IP再連接

[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:15:8c:06 brd ff:ff:ff:ff:ff:ff
    inet 192.168.16.129/24 brd 192.168.16.255 scope global noprefixroute dynamic ens33
       valid_lft 1072sec preferred_lft 1072sec
    inet6 fe80::2fee:c6a8:50e3:6e36/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

# ens33 我的IP地址就是192.168.16.129

2、我使用Navicat測試遠程連接。

注意NaviCat 12連接Sql Server時報錯 “未發現數據源名稱並且未指定默認驅動”,需要去安裝路徑裏面找到sqlncli_x64.msi

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章