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

发布了76 篇原创文章 · 获赞 47 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_40058321/article/details/104960848