If you’ve installed SQL Server on your SUSE machine, you’ll need some tools to connect to it and run queries, etc.
The sqlcmd and bcp utilities are good options for performing the most common tasks.
What are sqlcmd and bcp?
- sqlcmd is is a command-line utility for ad hoc, interactive execution of T-SQL statements and scripts and for automating T-SQL scripting tasks.
- bcp (bulk copy program) is a utility that can be used to import large numbers of new rows into SQL Server tables or to export data out of tables into data files.
Installation
The following steps install sqlcmd and bcp on to SUSE 12.
Add the Microsoft SQL Server repository to Zypper:
sudo zypper addrepo -fc https://packages.microsoft.com/config/sles/12/prod.repo
sudo zypper --gpg-auto-import-keys refresh
Now, install mssql-tools with the unixODBC developer package:
sudo zypper install -y mssql-tools unixODBC-devel
You’ll be prompted to accept the licence terms twice. If you agree with the terms, enter YES
on both occassions.
Add to PATH
You can optionally add the /opt/mssql-tools/bin/
to your PATH environment variable, so that you can run the tools without having to provide the full path.
To make sqlcmd/bcp accessible from the bash shell for login sessions:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
To make sqlcmd/bcp accessible from the bash shell for interactive/non-login sessions:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
Connect to SQL Server
Now that the sqlcmd and bcp are installed, you can use them to connect to SQL Server.
Here’s an example of connecting with sqlcmd.
Enter the following, but replace <YourPassword>
with your own password:
sqlcmd -S localhost -U SA -P '<YourPassword>'
Alternatively, you can omit -P '<YourPassword>'
and you will be prompted for it instead.
This assumes that SQL Server is installed on the local machine (localhost
).
To connect to a remote instance, change localhost
to the machine name or IP address, and be sure to open the applicable port on the firewall (port 1433 is the default for SQL Server).
Once you’ve connected successfully, you should see a prompt that looks like this:
1>
From here, you can use T-SQL to create databases, run queries, and more.
For now, enter the following code to check your version of SQL Server:
SELECT @@version
GO