MSSQL Server 命令行工具 for Linux
Posted ecsdoc
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MSSQL Server 命令行工具 for Linux相关的知识,希望对你有一定的参考价值。
1、添加安装源
[[email protected] yum.repos.d]# curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 193 100 193 0 0 104 0 0:00:01 0:00:01 --:--:-- 104
[[email protected] yum.repos.d]# ls
CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo msprod.repo mssql-server.repo
2、安装 mssql-tools 和 unixODBC 开发人员包
[[email protected] yum.repos.d]# yum install mssql-tools unixODBC-devel
3、将 /opt/mssql-tools/bin/
添加到 PATH 环境变量
[[email protected] /]# echo ‘export PATH="$PATH:/opt/mssql-tools/bin"‘ >> ~/.bash_profile [[email protected] /]# echo ‘export PATH="$PATH:/opt/mssql-tools/bin"‘ >> ~/.bashrc [[email protected] /]# cd ~ [[email protected] ~]# source .bashrc
4、检查是否安装成功:输入命令 sqlcmd
[[email protected] opt]# sqlcmd
Microsoft (R) SQL Server Command Line Tool
Version 17.3.0000.1 Linux
Copyright (c) 2012 Microsoft. All rights reserved.
usage: sqlcmd [-U login id] [-P password]
[-S server or Dsn if -D is provided]
[-H hostname] [-E trusted connection]
[-N Encrypt Connection][-C Trust Server Certificate]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w screen width]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-c cmdend]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-m errorlevel] [-V severitylevel] [-W remove trailing spaces]
[-u unicode output] [-r[0|1] msgs to stderr]
[-i inputfile] [-o outputfile]
[-k[1|2] remove[replace] control characters]
[-y variable length type display width]
[-Y fixed length type display width]
[-p[1] print statistics[colon format]]
[-R use client regional setting]
[-K application intent]
[-M multisubnet failover]
[-b On error batch abort]
[-D Dsn flag, indicate -S is Dsn]
[-X[1] disable commands, startup script, environment variables [and exit]]
[-x disable variable substitution]
[-? show syntax summary]
[[email protected] opt]#
5、Centos 连接数据库:
使用 SQL Server 名称 (-S),用户名 (-U) 和密码 (-P) 的参数运行 sqlcmd。 在本教程中,用户进行本地连接,因此服务器名称为 localhost
。 用户名为 SA
,密码是在安装过程中为 SA 帐户提供的密码。
sqlcmd -S localhost -U SA -P ‘<YourPassword>‘
[[email protected] opt]# sqlcmd -S localhost -U sa -P ‘xxxxxxxxxx‘
1>
以上是关于MSSQL Server 命令行工具 for Linux的主要内容,如果未能解决你的问题,请参考以下文章
MSSQL-Scripter,一个新的生成T-SQL脚本的SQL Server命令行工具
为 MSSQL Server docker 映像启用 XA 事务
sql [SQL查询片段]用于在命令行或通过R和其他工具使用SQL的快速代码段#tags:sql,R,text processing,命令li