When I'm using mysql client, I can configure my db credentials in ~/.my.ini.

How can I achieve similar thing with sqlcmd on Linux? Where and what filename I should create?

My goal is to avoid keep repeating hostname, user and passwords for every command.

  • If your goal is to avoid repeating, you can factorize the call with a generic function.
    – Hybris95
    Dec 11, 2018 at 14:06

2 Answers 2


The odbc.ini for mssql doesn't support the user and password.

Server parameter is used to specify port with syntax [protocol:]Server[,port]

Check /etc/odbcinst.ini for what driver name to use.

$ cat /etc/odbcinst.ini
[ODBC Driver 17 for SQL Server] # must match the 'Driver' in odbc.ini
Description=Microsoft ODBC Driver 17 for SQL Server

$ cat /etc/odbc.ini
Driver=ODBC Driver 17 for SQL Server

$ sqlcmd -D -S ExampleDataSourceName -U user 

MS SQL client is supporting unixODBC. So the credentials can be set in odbc.ini (e.g. ~/.odbc.ini, /etc/odbc.ini). The configuration file can be also specified by ODBCINI environment variable.

Sample content:

    Description = The Database using MyODBC Driver DSN
    SERVER = localhost
    PORT =
    USER = root
    Password = somePassword
    Database = the_db

See: Configuring and Testing iODBC.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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