安装SQL Server服务
微软的官方文档:安装 SQL Server 和 Red Hat 上创建数据库
安装必要条件:
必须 RHEL 7.3 或 7.4 机至少 2 GB的内存。
1. 添加yum源
各类yum源对应地址:https://packages.microsoft.com/config/rhel/7/
我们选择 "mssql-server-2017.repo"
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# wget https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo
[root@localhost yum.repos.d]# yum -y install mssql-server
2.安装MS SQL
[root@localhost ~]# /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): 3 ###选择版本,此处我选择社区免费版
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]:Yes ##输入Yes,同意许可的意思
Enter the SQL Server system administrator password: ##输入数据库管理员SA对应的密码
Confirm the SQL Server system administrator password: ##再次输入一遍
Configuring SQL Server...
The licensing PID was successfully processed. The new edition is [Express Edition].
ForceFlush is enabled for this instance.
ForceFlush feature is enabled for log durability.
Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server.service to /usr/lib/systemd/system/mssql-server.service.
Setup has completed successfully. SQL Server is now starting.
3.查看服务启动状态
[root@localhost ~]# 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 Mon 2018-07-16 10:10:23 CST; 52min ago
Docs: https://docs.microsoft.com/en-us/sql/linux
Main PID: 46685 (sqlservr)
CGroup: /system.slice/mssql-server.service
├─46685 /opt/mssql/bin/sqlservr
└─46705 /opt/mssql/bin/sqlservr
Jul 16 10:10:29 localhost.localdomain sqlservr[46685]: 2018-07-16 10:10:29.10 spid5s 8 transaction...ed.
Jul 16 10:10:29 localhost.localdomain sqlservr[46685]: 2018-07-16 10:10:29.20 spid5s 0 transaction...ed.
Jul 16 10:10:29 localhost.localdomain sqlservr[46685]: 2018-07-16 10:10:29.30 spid11s Polybase feat...ed.
Jul 16 10:10:29 localhost.localdomain sqlservr[46685]: 2018-07-16 10:10:29.30 spid11s Clearing temp...se.
Jul 16 10:10:30 localhost.localdomain sqlservr[46685]: 2018-07-16 10:10:30.00 spid11s Starting up d...b'.
Jul 16 10:10:30 localhost.localdomain sqlservr[46685]: 2018-07-16 10:10:30.45 spid20s The Service B...te.
Jul 16 10:10:30 localhost.localdomain sqlservr[46685]: 2018-07-16 10:10:30.45 spid20s The Database ...te.
Jul 16 10:10:30 localhost.localdomain sqlservr[46685]: 2018-07-16 10:10:30.53 spid20s Service Broke...ed.
Jul 16 10:10:30 localhost.localdomain sqlservr[46685]: 2018-07-16 10:10:30.54 spid5s Recovery is c...ed.
Jul 16 10:10:32 localhost.localdomain sqlservr[46685]: 2018-07-16 10:10:32.93 spid32s The activated pr...
Hint: Some lines were ellipsized, use -l to show in full.
4.防护墙设置,开放1433端口
sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent
sudo firewall-cmd --reload
安装SQL Server命令行工具
1. 下载yum源
curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
2.卸载旧版本工具,并安装新版本
yum remove unixODBC-utf16 unixODBC-utf16-devel
yum install -y mssql-tools unixODBC-devel
3.添加环境变量到系统PATH路径中
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
或者直接写入/==etc==/==profile==中
本地连接
sqlcmd -S localhost -U SA -P '<YourPassword>' ##显示密码
或
sqlcmd -S localhost -U SA -P ##密码加密方式不可见
常用操作
1.新建数据库
CREATE DATABASE TestDB
2.查询数据库
SELECT Name from sys.Databases
3.执行命令
GO ##有别于mysql, 命令的执行需要输入GO
4.插入数据
接下来创建一个新表 Inventory,然后插入两个新行。
在 sqlcmd 命令提示符中,将上下文切换到新的 TestDB 数据库:
USE TestDB
创建名为 Inventory 的新表:
CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)
将数据插入新表:
INSERT INTO Inventory VALUES (1, 'banana', 150); INSERT INTO Inventory VALUES (2, 'orange', 154);
要执行上述命令的类型 GO:
GO
5.退出 sqlcmd 命令提示符:
QUIT
从windows连接MS SQL服务器
下载客户端工具: [SSMS](https://download.microsoft.com/download/C/3/D/C3DBFF11-C72E-429A-A861-4C316524368F/SSMS-Setup-CHS.exe
) (此处注意一定要使用下载工具进行下载如迅雷,不能使用浏览器自带的下载工具,否则安装包会有问题,无法正常进行安装)
安装步骤较为简单,无限下一步就行。安装完成需要重启系统才能使用。
双击运行此客户端,输入服务器地址,账号和密码建立连接
本文由 Mr Gu 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Aug 24, 2018 at 05:36 pm