本文根据微软官方手册整理完成

This topic provides connection requirements and guidance for SQL Server vNext CTP 1.3 running on Linux. In most cases, the connection requirements and processes do not differ across platforms. This topic approaches the subject in the context of Linux and then points to other resources.

This topic is a walk-through. In this walk-through, you will use sqlcmd to connect to SQL Server vNext on Linux. After successfully connecting, you will use Transact-SQL (T-SQL) queries to create and populate a small database.

Tip

Sqlcmd is just one tool for connecting to SQL Server to run queries and perform management and development tasks. For other tools such as SQL Server Management Studio and Visual Studio Code, see the Develop and Manage areas.

Install the SQL Server command-line tools

Sqlcmd is part of the SQL Server command-line tools, which are not installed automatically with SQL Server on Linux. If you have not already installed the SQL Server command-line tools on your Linux machine, you must install them. For more information on how to install the tools, follow the instructions for your Linux distribution:

Connection requirements

To connect to SQL Server on Linux, you must use SQL Authentication (username and password). To connect remotely, you must ensure that the port SQL Server listens on is open. By default, SQL Server listens on TCP port 1433. Depending on your Linux distribution and configuration, you might have to open this port in the firewall.

Connect to SQL Server on Linux

In the following steps, connect to SQL Server vNext on Linux with sqlcmd.

Tip

On macOS, use sql-cli because sqlcmd and bcp are not available.

On your Linux box, open a command terminal.

Run sqlcmd with parameters for your SQL Server name (-S), the user name (-U), and the password (-P).

The following command connects to the local SQL Server instance (localhost) on Linux.

Copy

bash sqlcmd -S localhost -U SA -P ''

Tip

You can omit the password on the command-line to be prompted to enter it.

To connect to a remote instance, specify the machine name or IP address for the -S parameter.

Copy

bash sqlcmd -S 192.555.5.555 -U SA -P ''

Tip

If you get a connection failure, first attempt to diagnose the problem from the error message. Then review the connection troubleshooting recommendations.

Query SQL Server

After you connect to SQL Server you can run queries to return information or create database objects. If you are new to writing queries, see Writing Transact-SQL Statements. In the following steps, you will use sqlcmd to:

Query SQL Server for a list of the databases.

Use Transact SQL to create a database.

Create and populate a table in the new database.

Query the table.

To to complete each of these tasks, copy the Transact-SQL from the examples below into the sqlcmd session that you created in the previous step.

For example, this query returns the name of all of the databases.

Copy

sql

SELECT Name from sys.Databases;

GO

Create a database using the SQL Server default settings.

Copy

sql

CREATE DATABASE testdb;

GO

Use the database:

Copy

sql

USE testdb;

GO

Create a table in the current database:

Copy

sql

CREATE TABLE inventory (id INT, name NVARCHAR(50), quantity INT);

GO

Insert data into the new table:

Copy

sql

INSERT INTO inventory VALUES (1, 'banana', 150);

INSERT INTO inventory VALUES (2, 'orange', 154);

GO

Select from the table:

Copy

sql

SELECT * FROM inventory WHERE quantity > 152;

GO

To end your sqlcmd session, type QUIT.

Copy

sql

QUIT

In this walk-through you connected to SQL Server with sqlcmd, and created and populated a database. For more information on how to use sqlcmd.exe, see sqlcmd Utility.

Connect and query from Windows

It is important to note that SQL Server tools on Windows connect to SQL Server instances on Linux in the same way they would connect to any remote SQL Server instance. So, you can follow the same steps in this topic running sqlcmd.exe from a remote Windows machine. Just verify that you use the target Linux machine name or IP address rather than localhost. For other connection requirements, see connection troubleshooting recommendations.

For other tools that run on Windows but connect to SQL Server on Linux, see:

Next Steps

For other ways to connect to SQL Server on Linux, see the Develop and Manage areas.

query登录linux命令,在Linux系统中使用sqlcmd命令连接与查询SQL Server相关推荐

  1. ss流量查询 php,Linux_Linux怎么使用ss命令查看系统的socket状态,  Linux系统中,ss命令可用于 - phpStudy...

    Linux怎么使用ss命令查看系统的socket状态 Linux系统中,ss命令可用于查看系统的socket的状态,而socket作为系统的进程通信机制,了解其状态是很有必要的,下面小编就给大家介绍下 ...

  2. linux 杀掉php,Linux_在Linux系统中使用xkill命令杀掉未响应的进程,我们如何在Linux中杀掉一个资 - phpStudy...

    在Linux系统中使用xkill命令杀掉未响应的进程 我们如何在Linux中杀掉一个资源/进程?很明显我们会找出资源的pid然后用kill命令. 说的更明白一点,我们可以找到某个资源(比如termin ...

  3. linux sudo命令全称,你知道Linux系统中的sudo 命令吗?

    今天小编要跟大家分享的文章是关于Linux系统中sudo命令介绍.熟悉Linux操作系统的小伙伴们你们是否了解sudo命令.sudo 表示 "superuser do". 它允许已 ...

  4. 我的linux系统怎么输入pv,如何在Linux系统中使用pv命令

    本文介绍了如何在Linux系统中使用pv命令.内容很详细.有兴趣的朋友可以参考一下,希望对大家有帮助. PV 命令 PV由Andrew Wood开发,是Pipe Viewer的简称,意思是通过管道显示 ...

  5. linux ps-l命令详解,Linux系统中ps -l命令显示的英文含义

    Linux系统中ps -l命令显示的英文含义 UID:启动这些进程的用户. PID:进程的进程ID. PPID:父进程的进程号(如果该进程是由另一个进程启动的). C:进程生命周期中的CPU利用率. ...

  6. linux系统下的shell是什么,Linux系统中shell各命令的区别有什么?

    今天小编要跟大家分享的文章是关于Linux系统中shell各命令的区别有什么?喜欢Linux系统并对此感兴趣的小伙伴们快来一起看一看吧~希望对你有所帮助. 1.xargs作用: (1)将前一个命令的标 ...

  7. Linux操作系统中man命令的用法,Linux 系统中的MAN命令使用祥解

    Linux 系统中的MAN命令使用祥解 在使用Linux命令或程序的过程中,大家免不了要看看命令和程序的帮助文档.这就要使用到man命令.下面就man命令使用的方法具体说一下: 1.man 的使用语法 ...

  8. Linux系统怎么使用扫描仪,Linux系统中Nmap扫描命令的使用方法 -电脑资料

    我们可以使用ping扫描的方法(-sP),与fping的工作方式比较相似,它发送icmp回送请求到指定范围的ip地址并等待响应,证明主机正在运行,反之,则无法判断主机是否开机或者是否在网络上互连. 扫 ...

  9. linux管道命令详解,Linux系统中的管道命令的用法详解

    Linux系统中管道命令是linux系统的一个强大之处.下面由学习啦小编为大家整理了Linux系统中的管道命令的用法详解的相关知识,希望对大家有帮助! Linux系统中的管道命令的用法详解 管道命令操 ...

最新文章

  1. RBAC新解 - 基于资源的权限管理
  2. weblogic在linux服务器上部署应用
  3. ×××生成算法的分析
  4. 7个步骤,帮您轻松实现云迁移
  5. FIR调用DSP48E_05
  6. 解决安卓模拟器没有网络的问题,刚开的做RN的我遇见这个问题真很头疼,所以希望看到我这篇文章能够解决。
  7. idea插件开发(02)---相关概念介绍
  8. [bzoj4568][Scoi2016]幸运数字
  9. js url解码gbk_使用js解码url里的gbk汉字编码
  10. 25匹马,5个跑道,不用外界工具怎样选出最快的5匹,要次数最短
  11. MVC、MVP与MVT
  12. 职业教育利益相关者的相关论述及研究不足
  13. 大盘点 | 性能最强的目标检测算法
  14. Bootstrap5 弹出框
  15. 看2022年卡塔尔世界杯有感
  16. 分享一个SlideShare:《做卓有成效的程序员》
  17. 汽车软件的SOA理解
  18. git安装 苹果笔记本_个人博客第5篇——安装node.js和Hexo
  19. Folder Sniffer
  20. 华为软件训练营Java_华为软件精英挑战赛-如何提交打包Java代码(运行打包)

热门文章

  1. 2019年春运贵州道路客运预计达6700万人次
  2. [转]Tomcat启动报错:AnnotationConfigBeanDefinitionParser are only available on JDK 1.5 and higher...
  3. 大杂烩 -- 四种生成和解析XML文档的方法详解
  4. [hadoop读书笔记] 第十五章 sqoop1.4.6小实验 - 将mysq数据导入hive
  5. qt 窗口自绘、鼠标响应拖动窗口
  6. 【oracle案例】ORA-01102: cannot mount database in EXCLUSIVE mode .
  7. 互联网把农业推向“科技仙境”
  8. 它身上的飞秋 战衣给他添上了英武的气势
  9. 我的程序都是这样命名的:openeim001
  10. SEO人生衔接后用户可随时随地同他的合作伙伴协同工作