On November 16, 2016 Microsoft announced the public preview of the next release of SQL Server on Linux and Windows, which brings the power of SQL Server to both Windows – and for the first time ever – Linux. SQL Server enables developers and organizations to build intelligent applications with industry-leading performance and security technologies using their preferred language and environment. With the next release of SQL Server, we can develop applications with SQL Server on Linux, Windows, Docker, or macOS (via Docker) and then deploy to Linux, Windows, or Docker, on-premises or in the cloud.
But only today I have had the time to install it and try it!
So this article provides a walkthrough of how to install SQL Server vNext CTP 1.1 on Ubuntu 16.04 and 16.10. (Note: doesn't work on 14.04 because the OpenSSL-package is outdated).
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server.list | sudo tee /etc/apt/sources.list.d/mssql-server.list
sudo apt-get update sudo apt-get install -y mssql-server
sudo /opt/mssql/bin/sqlservr-setup
systemctl status mssql-server
In order to upgrade the mssql-server package, follow these steps:
sudo apt-get update
sudo apt-get install mssql-server
These commands will download the newest package and replace the binaries located under /opt/mssql/ . The user generated databases and system databases will not be affected by this operation.
In order to remove the mssql-server package, follow these steps:
sudo apt-get remove mssql-server
sudo rm -rf /var/opt/mssql/
If you want to check whether it works or not, do not forget to switch off the firewall
iptables -F iptables -P INPUT ACCEPT
And to permanently open port 1433 (sql-server default-port)
iptables -A INPUT -p tcp --dport 1433 -j ACCEPT sudo apt-get install iptables-persistent sudo netfilter-persistent save sudo netfilter-persistent reload
or if you use ufw, you can do the same by typing less with
ufw allow 1433/tcp
You can stop, start, or restart the SQL Server service as needed using the following commands:
sudo systemctl stop mssql-server sudo systemctl start mssql-server sudo systemctl restart mssql-server
To start sql-server at boot-time:
systemctl enable mssql-server
To disable SQL-Server-start at boot-time:
systemctl disable mssql-server
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt-get update sudo apt-get install mssql-tools unixodbc-dev-utf16
To update to the latest version of 'mssql-tools' run the following commands:
apt-get refresh apt-get update mssql-tools
Run sqlcmd with parameters for your SQL Server name (-S), the user name (-U), and the password (-P).
The following command connects to the local SQL Server instance (localhost) on Linux.
sqlcmd -S localhost -U SA -P <YourPassword>
To connect to a remote instance, specify the machine name or IP address for the -S parameter.
sqlcmd -S <ServerIP> -U SA -P <YourPassword>
For example, this query returns the name of all of the databases.
SELECT Name from sys.Databases; GO
Create a database using the SQL Server default settings.
CREATE DATABASE testdb; GO
Use the database:
USE testDatabase; GO
Create a table in the current database:
CREATE TABLE Table1 (id INT, name NVARCHAR(50), quantity INT); GO
Insert data into the new table:
INSERT INTO Table1 VALUES (1, 'Item1', 10); INSERT INTO Table1 VALUES (2, 'Item2', 15); GO
Select from the table:
SELECT * FROM Table1 WHERE quantity > 12; GO
To end your sqlcmd session, type
QUIT
or
Exit
It is important to note that SQL Server tools on Windows connect to SQL Server instances on Linux in the same way they would connect to any remote SQL Server instance. So, you can follow the same steps in this topic running sqlcmd.exe from a remote Windows machine using :