首页 > 数据库 >SQLSERVER单机安装配置

SQLSERVER单机安装配置

时间:2023-03-10 10:32:39浏览次数:36  
标签:单机 clear SQLSERVER back Server SQL go 安装 mssql


安装配置

SQL server2017版本软件包

mssql-server-14.0.3238.1-19.x86_64.rpm
mssql-tools-17.4.1.1-1.x86_64.rpm
msodbcsql-13.1.9.2-1.x86_64.rpm
msodbcsql17-17.4.2.1-1.x86_64.rpm

配置本地yum源,之后使用yum安装rpm包

yum install msodbcsql-13.1.9.2-1.x86_64.rpm
yum install msodbcsql17-17.4.2.1-1.x86_64.rpm
yum install mssql-server-14.0.3238.1-19.x86_64.rpm
yum install mssql-tools-17.4.1.1-1.x86_64.rpm

配置mssql

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

Enter the SQL Server system administrator password:
The specified password does not meet SQL Server password policy requirements because it is too short. The password must be at least 8 characters
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 Edition: Core-based Licensing].
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.

sqlcmd配置

sqlcmd登陆时报如下错误

Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2746

因系统进行安全加固,对ssl进行了升级,Sql Server和SSMS依赖的SSL是1.0版本的,由于版本不一致造成无法链接
解决方案如下:

# 先停止MSSQL
sudo systemctl stop mssql-server

# 编辑服务配置
sudo systemctl edit mssql-server

# 在打开的编辑器中输入
[Service]
Environment="LD_LIBRARY_PATH=/opt/mssql/lib"
#输入完保存

# 给MSSQL创建指向SSL1.0的链接
sudo ln -s /usr/lib64/libssl.so.1.0.2k /opt/mssql/lib/libssl.so
sudo ln -s /usr/lib64/libcrypto.so.1.0.2k /opt/mssql/lib/libcrypto.so

数据目录配置

修改数据库数据文件及备份文件位置

mkdir -p /mssql/data
mkdir -p /backup
chown -R mssql:mssql /mssql/
chown -R mssql:mssql /backup/
/opt/mssql/bin/mssql-conf set filelocation.defaultdatadir /mssql/data
/opt/mssql/bin/mssql-conf set filelocation.defaultlogdir /mssql/data
/opt/mssql/bin/mssql-conf set filelocation.defaultbackupdir /backup
/opt/mssql/bin/mssql-conf set filelocation.defaultdumpdir /backup

设置排序规则

修改数据库排序规则

/opt/mssql/bin/mssql-conf set-collation 
Latin1_General_CI_AS

备份恢复

数据备份

创建备份脚本

#!/bin/bash
source /etc/profile

# 以下是配置信息
user=sa
passwd=Password01
back_path=/backup
db_list="[Test-clear] [Freem]"
back_time=`date +%Y%m%d`
for db_name in $db_list
do
echo "==============开始备份数据库[$db_name]=============" >> log$back_time.log
back_filename=$back_path/$db_name$back_time
sqlcmd -S localhost -U $user -P $passwd -d master -Q "BACKUP DATABASE $db_name to disk='$back_filename.bak'"
if [ -e $back_filename.bak ];then
echo "==============数据库[$db_name] 备份成功!=============" >> log$back_time.log
else
echo "==============数据库[$db_name] 备份失败!=============" >> log$back_time.log
fi
done

设置定时任务

crontab -e
0 23 * * * /root/scripts/back.sh # 每天晚上23点执行

备份还原

获取数据库逻辑名

1> restore  filelistonly from disk = '/tmp/Test-clear.bak'
2> go

数据库还原,库名包含特殊字符,需要使用中括号包围

RESTORE DATABASE [TaskProcess-clear] FROM DISK = '/tmp/TaskProcess-clear.bak'
WITH MOVE 'TaskProcess-clear' TO '/mssql/data/TaskProcess-clear.mdf',
MOVE 'TaskProcess-clear_log' TO '/mssql/data/TaskProcess-clear_log.ldf'
GO

权限分配

登录名只有登进数据库的功能 ,登录名可以映射用户名, 这样就有了相应的权限

本方案将创建两个用户并赋予数据库权限,将两个用户名映射到登录名,登录后可以操作两个数据库

创建登录名

create login aps with password='Aps2022'
go

创建用户名Test-clear

use [Test-clear]
go
create user Test-clear for login aps
go
# 赋予数据库权限
exec sp_addrolemember 'db_owner', 'Test-clear'
go
# 设置用户默认schema
alter user Freemwith default_schema=Test-clear;
go

创建用户名Freem

use Freem
go
create user Freem for login aps
go
# 赋予数据库权限
exec sp_addrolemember 'db_owner', 'Freem'
go
设置用户默认schema
alter user Freemwith default_schema=Freem;
go

日常操作

sqlcmd登录

# sqlcmd -U sa -P Test2016

查询数据库版本

1> select @@version
2> go
-----------------------------------------------------------------------------------------------------------------------
Microsoft SQL Server 2017 (RTM-CU17) (KB4515579) - 14.0.3238.1 (X64)
Sep 13 2019 15:49:57
Copyright (C) 2017 Microsoft Corporation
Enterprise Edition: Core-based Licensing (64-bit) on Linux (Red Hat Enterprise Linux Server 7.6 (Maipo))

(1 rows affected)

查看表结构,如表名前指定schema,需要用单引号包围,否则报错

sp_help table_name;
sp_columns table_name;
#表名指定schema示例
sp_help 'sys.schemas'
#扩展
sp_helpdb
sp_helpindex
sp_helpfile

查看数据库信息

select * from sysdatabases
go

查看schema信息

use Freem
go
select * from sys.schemas
go

查看对象信息

select * from sysobjects
go


标签:单机,clear,SQLSERVER,back,Server,SQL,go,安装,mssql
From: https://blog.51cto.com/u_14852239/6112557

相关文章

  • Ubuntu18.04.6 server 安装
    Ubuntu18.04.6serverLTS安装对比Ubuntu18.04.2,Ubuntu18.04.6以后的版本安装页面都采用的新页面1、第一行安装Ubuntu2、语言选English;键盘布局选English(US)美式英......
  • python环境安装
    安装python1、python下载链接:https://www.python.org/downloads/windows/2、安装python 傻瓜式安装请注意,一定要勾选 AddPython3.8toPATH,这样可以将Python命令......
  • 安装python3 for Centos
     以安装3.7.5为例下载安装包wgethttp://npm.taobao.org/mirrors/python/3.7.5/Python-3.7.5.tar.xz 解压xz-dPython-3.7.5.tar.xztar-xfPython-3.7.5.tar......
  • 在CentOS中用Linux命令行测试网速/带宽安装
    导读在使用Centos的时候,有没有想过,如果不用测速网站的话,如何测试网络速度呢?下面分享一个使用speedtest的方法。安装speedtest-clispeedtest-cli是一个用Python编......
  • CentOS7 安装 docker
    CentOS7安装卸载docker查看内核版本,需要3.10以上uname-r更新yum软件包索引yummakecachefast卸载旧版本yumremovedocker\docker-cli......
  • Ubantu系统安装软件的方法
    方法一、直接在ubantu软件商店安装方法二、使用apt命令安装1.不止Ubantu,Dedbian系统的(Debain、Ubantu、Deepin、Raspbian等)都可以使用apt命令安装软件。2.Uba......
  • Docker 安装可视化工具 Portainer 中文版
    参考文档:安装中文版portainer-ce-简书(jianshu.com)(21条消息)Docker可视化工具Portainer的安装和使用_琦彦的博客-CSDN博客安装中文版portainer-ce-简书(jian......
  • docker-compose安装NginxProxyManager中文版
    参考文档:NginxProxyManager中文版安装教程反向代理神器——NginxProxyManager_蒟蒻颖的博客-CSDN博客_nginxproxymanagernginx开源可视化代理管理器nginx-proxy-man......
  • redis之列表-redis之hash-redis其他操作-redis管道-django中使用redis-celery介绍和安
    目录redis之列表-redis之hash-redis其他操作-redis管道-django中使用redis-celery介绍和安装-celery快速使用-celery包结构今日内容详细1redis之列表2redis之hash3redis......
  • centos stream9 源码安装 amule 2.3.3
    下载amule源码cdaMule-2.3.3mkdirbuild-kuncdbuild-kun../configure缺少依赖zlibsudodnfinstallzlib-devel重复执行../configure缺少wxwidgets从源代码......