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 Answers
Install FreeTDS. Once configured you'll be able to use tsql to query SQL Server from bash.
2 Comments
TrueBlue10
Hi, I've installed the FreeTDS and connected to the SQL Server. Thank you. But how can I make query?
TrueBlue10
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.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
TrueBlue10
I just saw SUSE and redhat version, but my OS is debian.
Razvan Stefanescu
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.
TrueBlue10
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.
mysqldump -h $the_server -u $user --databases $database --tables $table -p$password