15

I use a Mac to develop web apps. Our runtime is Java, our web server is Jetty, and our IDE is Eclipse. So our whole stack can be used from Mac and Windows natively … with the exception of our database, which is MS SQL Server (ranging from 2000 to 2008 depending on the application). I want a Unix command-line client for MS SQL Server.

I don't like any of the OS X GUI clients for SQL Server – I find them tedious and not very Mac-like – so for the time being I use SQL Server 2008 Management Studio, on Windows XP, via VMWare Fusion. But it's still a huge pain to launch and quit, it eats up my RAM while it's running, and it poisons my Time Machine backups by altering several 2GB files on disk every time I use it.

I like how MySQL can be used from the command line, so that seems like a great way to quickly get to my database and investigate a bug or add some test data. If only I could use SQL Server that way! Short of implementing a command line client myself using straight JDBC, there anything out there that makes this possible?

Community
  • 1
  • 1
easeout
  • 8,665
  • 5
  • 43
  • 51

7 Answers7

11

This open source node app that came out in 2014, sql-cli, provides a useful command line console for Mac OS X and other desktops.

dcorking
  • 1,146
  • 1
  • 14
  • 24
9

Microsoft now provides OS X binaries of Command Line Tools for SQL Server, including sqlcmd, along with a first-party ODBC driver. This should, in theory, support connecting with Windows Authentication if the Mac has Kerberos configured accordingly—something the sql-cli tool doesn't likely offer.

These are distributed as Homebrew packages:

$ brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
$ brew update
$ ACCEPT_EULA=y brew install --no-sandbox msodbcsql mssql-tools

Connecting OS X host as a client to SQL Server running in Docker:

$ sqlcmd -S 127.0.0.1 -U sa -P 'yourStrong(!)Password'
1> SELECT @@VERSION AS 'SQL Server Version'
2> GO
SELECT @@VERSION AS 'SQL Server Version'

SQL Server Version
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64)
    Aug 22 2017 17:04:49
    Copyright (C) 2017 Microsoft Corporation
    Developer Edition (64-bit) on Linux (Ubuntu 16.04.3 LTS)

(1 rows affected)
1> quit

You can configure DSNs in ~/.odbc.ini:

# Give -D to connect using a DSN:
# sqlcmd -S DockerMS -D -U user -P password

[DockerMS]
Driver = ODBC Driver 13 for SQL Server
Server = 127.0.0.1,1433
Database = YourDefaultDB

where the Driver setting matches the name registered with unixODBC by the installation process, see odbcinst -q -d.

ches
  • 6,382
  • 2
  • 35
  • 32
4

Install FreeTDS and then you can run sqsh form the terminal

Chris Farmiloe
  • 13,935
  • 5
  • 48
  • 57
1

Free, open source, Java based: SQuirreL?

You probably won't get a command line based tool for SQL Server in the same way you'd do stuff for MySQL or Oracle. Almost every command and action that you need to do are SQL commands: you just need a SQL client

gbn
  • 422,506
  • 82
  • 585
  • 676
  • 1
    I upvoted because this was right at the time, (back in 2011) even though the OP said "I don't like any of the OS X GUI clients for SQL Server ". Squirrel is not Mac-like, but I prefer it to the command line clients just for writing and running pure SQL code for SQL Server and PostgreSQL: I don't know why the OP found it tedious and maybe other readers won't. – dcorking Oct 13 '16 at 20:21
1

Try using the Azure Data Studio, cross-platform tool. I am using as a SQL client On MAC and fell it is the best. It is free and User-friendly, unlike other Free SQL clients.

Avdhoota
  • 451
  • 4
  • 20
1

Even though I prefer using Azure Data Studio on the Mac, I used to work on the command line with MS SQL for a little while. I did this using the cross-platform tool sql-cli.

Assuming you have installed npm, run the below command on the terminal -

    npm install -g sql-cli

if you have a permission error, try running this as root/Administrator, but this time by prepending the sudo command.

    sudo npm install -g sql-cli

Now connect to the MS SQL server

    mssql -u sa -p myPassw0rd

You should expect something of this sort:

    Connecting to localhost...done

      sql-cli version 0.6.2
      Enter ".help" for usage hints.
      mssql>

To check is your SQL Server is running run a test by typing in the command:

    select @@version

If your server is running, you should see an output similar to this:

    Microsoft SQL Server 2019 (RTM-CU4) (KB4056498) - 15.0.2022.28 (X64) 
        May 9 2020 10:39:09 
        Copyright (C) 2017 Microsoft Corporation
        Developer Edition (64-bit) on Linux (Ubuntu 16.04.3 LTS)

    1 row(s) returned

    Executed in 1 ms
    mssql>
0

$ pip install mssql-cli

You can find more info in https://learn.microsoft.com/pt-br/sql/tools/mssql-cli?view=sql-server-ver15 for more info.