4

Our company has a db (SQL Server) in another country. I have the host name, username and the password of the db. I want to extract data from the database through bash shell and put them into local file. How can I do that?

2
  • 1
    Is it MySQL or...? If so, you can make use of mysqldump -h $the_server -u $user --databases $database --tables $table -p$password Commented Mar 26, 2014 at 14:46
  • 2
    OP stated that the db is SQL server. Commented Mar 26, 2014 at 14:47

2 Answers 2

4

Install FreeTDS. Once configured you'll be able to use tsql to query SQL Server from bash.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, I've installed the FreeTDS and connected to the SQL Server. Thank you. But how can I make query?
The problem is solved by installing FreeTDS. And the query sentence should be select * from blah where id = 1 and we need a go at the end of query.
1

You will need some command line utilities export data from MS SQL Server. One option is to install Microsoft ODBC Driver for SQL Server on Linux and then use some command line utility like sqlcmd.

MSDN page for Microsoft ODBC Driver: http://msdn.microsoft.com/en-us/library/hh568451.aspx

Example of using sqlcmd to export data to a CSV file: How to export data as CSV format from SQL Server using sqlcmd?

3 Comments

I just saw SUSE and redhat version, but my OS is debian.
I do not have a Debian to play with, but I found a tutorial here: code.google.com/p/odbc/wiki/… I hope it works for you.
Hi, thank you for your advice. I tried to install sqlcmd on my OS, but it seems only support 64bit operating system. So I try to use FreeTDS and it works. But thank you very much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.