[sql-server] What are some ways of accessing Microsoft SQL Server from Linux?

We have a Windows machine running SQL Server 2005, and we need to be able to run some database queries on it from a Linux box. What are some of the recommended ways of doing this? Ideally, we would want a command-line utility similar to sqlcmd on Windows.

This question is related to sql-server

The answer is



There is an abstraction lib available for PHP. Not sure what your client's box will support but if its Linux then certainly should support building a PHP query interface with this: http://adodb.sourceforge.net/ Hope that helps you.


sql-cli is a nodejs based cross platform command line interface for sql server. You can install it via npm https://www.npmjs.org/package/sql-cli

It can connect to both on-premise and sql azure instance.


Mono contains an ADO.NET provider that should do this for you. I don't know if there is a command line utility for it, but you could definitely wrap up some C# to do the queries if there isn't.

Have a look at http://www.mono-project.com/TDS_Providers and http://www.mono-project.com/SQLClient


pymssql is a DB-API Python module, based on FreeTDS. It worked for me. Create some helper functions, if you need, and use it from Python shell.


Since November 2011 Microsoft provides their own SQL Server ODBC Driver for Linux for Red Hat Enterprise Linux (RHEL) and SUSE Linux Enterprise Server (SLES).

It also includes sqlcmd for Linux.


There is a nice CLI based tool for accessing MSSQL databases now.

It's called mssql-cli and it's a bit similar to postgres' psql.

Gihub repository page

Install for example via pip (global installation, for a local one omit the sudo part):

sudo pip install mssql-cli

You don't say what you want to do with the resulting data, but if it's general queries for development/maintenance then I'd have thought Remote Desktop to the windows server and then using the actual SQL Server tools on their would always have been a more productive option over any hacked together solution on Linux itself.


If you use eclipse you can install Data Tools Platform plugin on it and use it for every DB engines including MS SQLServer. It just needs to get JDBC driver for that DB engine.


sqsh (http://www.sqsh.org/) + freetds (http://www.freetds.org)

sqsh was primarily an isql replacement for Sybase SQL Server (now ASE) but it works just fine for connecting to SQL Server (provided you use freetds).

To compile, simply point $SYBASE to freetds install and it should work from there. I use it on my Mac all day.

The best part of sqsh are the advanced features, such as dead simple server linking (no need to set up linked servers in SQL Server), flow control and looping (no more concatenating strings and executing dynamic SQL), and invisible bulk copy/load.

Anyone who uses any other command line tool is simply crazy! :)


I'd like to recommend Sqlectron. Besides being open source under MIT license it's multiplatform boosted by Electron. Its own definition is:

A simple and lightweight SQL client desktop with cross database and platform support

It currently supports PostgreSQL, MySQL, MS SQL Server, Cassandra and SQLite.


valentina-db it has free version for sql server
.rpm and .deb
serial id will be sent by email after registration

https://www.valentina-db.com/en/

https://valentina-db.com/en/store/category/14-free-products

valentina-db


I was not confortable with the freetds solution, it's why i coded a class (command history, autocompletion on tables and fields, etc.)

http://www.phpclasses.org/package/8168-PHP-Use-ncurses-to-get-key-inputs-and-write-shell-text.html