环境:Ubuntu 18.04; 需要连接互联网 Ubutun 20.04, 16.04 可将路径中的18.04分别替换为 20.04, 16.04
Ubuntu:在 Linux 上安装 SQL Server - SQL Server | Microsoft Docs: https://docs.microsoft.com/zh-cn/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-ver15
apt update apt upgrade
# 可能会导入失败,需根据提示安装缺失的组件 wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2019.list)"
sudo apt-get update sudo apt-get install -y mssql-server
# 根据提示选择版本,并设置SA密码 # SA 帐户密码要求(最少 8 个字符,包括大写和小写字母、十进制数字或非字母数字符号)。 sudo /opt/mssql/bin/mssql-conf setup
systemctl status mssql-server --no-pager
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt-get update sudo apt-get install mssql-tools unixodbc-dev
# 备注:以下命令,更新 mssql-tools sudo apt-get update sudo apt-get install mssql-tools
/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
# -S Sql Server 名称, -U 用户名, -P 密码 # 若省略密码,会收到密码输入提示 sqlcmd -S localhost -U SA -P '<YourPassword>'
1>
使用 PowerShell 管理 Linux 上的 SQL Server - SQL Server | Microsoft Docs: https://docs.microsoft.com/zh-cn/sql/linux/sql-server-linux-manage-powershell?view=sql-server-ver15
# 可能会有提示,需根据提示进行选择 Install-Module -Name SqlServer
about_Execution_Policies - PowerShell | Microsoft Docs: https://docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.1
(我查阅的时候,还是机翻,效果不太好,可以和英文版结合看)
Get-ExecutionPolicy -List
Set-ExecutionPolicy -ExecutionPolicy <PolicyName> -Scope <scope>范例
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process
AllSigned
, Bypass
, Default
, RemoteSigned
, Restricted
, Undefined
, Unrestricted
MachinePolicy
, UserPolicy
, Process
(仅当前会话), CurrentUser
(当前用户), LocalMachine
下载 SQL Server PowerShell 模块 - SQL Server | Microsoft Docs: https://docs.microsoft.com/zh-cn/sql/powershell/download-sql-server-ps-module?view=sql-server-ver15
Import-Module SqlServer
Get-Module -Name SqlServer
PowerShell 应显示类似以下输出
ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Script 21.1.18245 SqlServer {Add-RoleMember, Add-SqlAvailabilityDatabase, Add-SqlAvail...
# 会提示输入实例的主机名/IP地址 $serverInstance = Read-Host "输入实例名称" # 会弹出输入凭据的对话框,为用于连接 Sql 的用户名和密码 $credential = Get-Credential # 连接到服务器并获取配置 Get-SqlInstance -ServerInstance $serverInstance -Credential $credential
PowerShell 应显示类似以下输出
Instance Name Version ProductLevel UpdateLevel HostPlatform HostDistribution ------------- ------- ------------ ----------- ------------ ---------------- 47.106.238.147 15.0.4123 RTM CU10 Linux Ubuntu