Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does anyone know of a ready made1 command line tool that would allow me to connect from a linux client to a sql-server?

I want to be able to run arbitrary queries, but most of the time I want to be able to take a database dump and then restore it.

This has to be scriptable as it will integrate in an automated build environment.

1FYI: My only other alternative is to write something. I'll probably use perl and DBI

share|improve this question

closed as off-topic by dezso, Max Vernon, Paul White, Colin 't Hart, RolandoMySQLDBA Jun 3 '15 at 10:15

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Shopping list question - questions about which tool, library, product or resource you should use are off-topic here because they quickly become obsolete and often are just about the preferences of the answerer. If you have an issue with or a question about a specific tool, please revise your question to conform to that scope." – dezso, Max Vernon, Paul White, Colin 't Hart, RolandoMySQLDBA
If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 4 down vote accepted

I found tsql and while its main purpose may lie elsewhere it covers my needs.

It is included in the EPEL package. I installed it with this:
rpm -Uvh

FreeTDS(May 14, 2011)                                    FreeTDS(May 14, 2011)

       tsql - utility to test FreeTDS connections and queries

       tsql   { -S servername [-I interface] | -H hostname -p port }
              -U username [-P password] [-o options]

       tsql   -C

       tsql  is  a diagnostic tool provided as part of FreeTDS. It uses the TDS protocol directly to con-
       nect to Sybase or Microsoft SQL Servers, and allows the user to issue queries that test the  capa-
       bilities of FreeTDS.

       tsql  is  *not* a replacement for a complete isql, such as sqsh (  It is designed to
       rely on the lowest level FreeTDS library, tdslib, as a way to isolate potential bugs in the proto-
       col implementation.
share|improve this answer

You might want to look at SQL Workbench/J

It's Java/JDBC based thus runs fine on Linux

It supports a GUI mode, interactive commandline usage (no GUI) and can be run in batch mode. It also supports exporting into various formats in order to take the "dump".

share|improve this answer

You can use sql-cli to connect to both on-premise and sql azure instance. It allows you to run one-off queries or run script files using .read command

Usage: mssql [options]


-h, --help                     output usage information
-V, --version                  output the version number
-s, --server <server>          Server to conect to
-u, --user <user>              User name to use for authentication
-p, --pass <pass>              Password to use for authentication
-o, --port <port>              Port to connect to
-t, --timeout <timeout>        Connection timeout in ms
-d, --database <database>      Database to connect to
-q, --query <query>            The query to execute
-v, --tdsVersion <tdsVersion>  Version of tds protocol to use [7_4, 7_2, 7_3_A, 7_3_B, 7_4]
-e, --encrypt                  Enable encryption
-f, --format <format>          The format of output [table, csv, xml, json]
share|improve this answer
Any way to tell the cli to use Windows Authentication? – TCopple Aug 11 '14 at 15:43
@TCopple nop, it does not support windows authentication. – Hasan Khan Aug 11 '14 at 17:37

Microsoft make a SQL Server ODBC driver for Linux, although it's binary only and only runs on certain 64 bit RHEL builds.1 Anything that can consumbe ODBC (through the unixODBC driver suite) can use it. For scripting, you could use python, perl, or anything that plays with unixODBC to automate tasks.

The package also comes with versions of bcp and sqlcmd. Sqlcmd will support interactive querying or allow queries to be embedded in shell scripts.

  1. Although you can bring it up on other builds by installing the relevant libraries - a process well known to people bringing Oracle up on Linux.
share|improve this answer

SqlTool is a JDBC CLI for interactive and automation uses. It does support exporting and importing in a fashion similar to Oracle's Sql*Loader (if you're familiar with that).

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.