Mirror site is read only www.netnr.com
netnr/ install-sqlserver 2018-12-07 08:02
CentOS7安装mssql-server
# 下载 Microsoft SQL Server Red Hat 存储库配置文件
curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2019.repo

yum install mssql-server # 安装

# 更改2GB内存限制为512MB(可选)
cd /opt/mssql/bin
mv sqlservr sqlservr.old
python
oldfile = open("sqlservr.old", "rb").read()
newfile = oldfile.replace("\\x00\\x94\\x35\\x77", "\\x00\\x80\\x84\\x1e")
open("sqlservr", "wb").write(newfile)
exit()
chmod -R 755 ./sqlservr
# https://blog.csdn.net/qq_37604508/article/details/80733507


# 运行包安装完成后mssql-conf 安装并按照提示操作以设置 SA 密码,并选择你的版本
/opt/mssql/bin/mssql-conf setup

# 选择 SQL Server 的一个版本:
#   1) Evaluation (免费,无生产许可,180 天限制)
#   2) Developer (免费,无生产许可)
#   3) Express (免费)
#   4) Web (付费版)
#   5) Standard (付费版)
#   6) Enterprise (付费版)
#   7) Enterprise Core (付费版)
#   8) 我通过零售渠道购买了许可证并具有要输入的产品密钥。

# 输入版本(1-8): 1
# 同意许可条款,输入yes
# 设置SQL密码,输入二次 请确保为 SA 帐户指定强密码(最少 8 个字符,包括大写和小写字母、十进制数字和/或非字母数字符号)

/opt/mssql/bin/mssql-conf set-collation # 设置排序规则 Chinese_PRC_CI_AS

systemctl status mssql-server # 查看运行状态
systemctl start mssql-server # 启动服务
systemctl stop mssql-server # 停止服务
systemctl restart mssql-server # 重启服务

# 再配置防火墙


# SQL Server 命令行工具

curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo # 下载安装源
yum install -y mssql-tools unixODBC-devel # 安装

# 添加/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

yum install -y mssql-server-agent # 代理安装(可选)
yum install -y mssql-server-fts # 全文搜索安装(可选)

# 使用sqlcmd进行本地连接
sqlcmd -S localhost -U SA -P '<YourPassword>'
sqlcmd -S localhost -U SA
# 如果成功,应会显示 sqlcmd 命令提示符:1>

yum update mssql-server # 更新SQL Server
yum remove mssql-server # 卸载 SQL Server

# 更改默认数据或日志目录位置(如附加mdf文件,确保文件所属mssql用户组)
chown mssql /netnr/data
chgrp mssql /netnr/data
/opt/mssql/bin/mssql-conf set filelocation.defaultdatadir /netnr/data
/opt/mssql/bin/mssql-conf set filelocation.defaultlogdir /netnr/data

/opt/mssql/bin/mssql-conf set memory.memorylimitmb 800 # 内存限制设置,单位MB
/opt/mssql/bin/mssql-conf set network.tcpport 12345 # 更改 SQL Server 侦听连接的 TCP 端口(默认1433)
systemctl restart mssql-server # 重启服务生效

cat /var/opt/mssql/mssql.conf # 查看配置

rpm -qa | grep mssql # 查看版本
find / -name mssql # 安装路径

# help
https://docs.microsoft.com/zh-cn/sql/linux/sql-server-linux-overview?view=sql-server-ver15