Once you’ve installed Microsoft SQL Server on Linux, you’ll want to make sure it’s configured as you’d like it to be. There are a few ways to do this, and today we’ll look at two: environment variables and the mssql-conf binary.
Make sure you’ve read our installation guide before we begin. The guide will assume you’ve got a working installation of MS SQL Server on Ubuntu. Other Linux variants should be similar, but you should double-check for differences in how commands are run.
Setting Configuration with mssql-conf
If you’re running SQL Server directly on your Linux machine, then the recommended way to change configuration is through the mssql-conf binary that was installed alongside your SQL Server installation.
As a simple example, we’ll look at changing the port that SQL Server runs on. By default, the port is set to 1433 but you may want to change it for security reasons. For example, we’ll set it to 14330. To change the port, start by running mssql-conf with the new port number:
sudo /opt/mssql/bin/mssql-conf set network.tcpport 14330
You should get back a message indicating the port has been updated. Now, you’ll need to restart the server so the configuration changes can take effect:
sudo systemctl restart mssql-server
The next time you connect to the server, you’ll need to use the updated port number. For a typical configuration change, that’s all that needs to happen. Using the mssql-conf binary, you can change everything from the log or data directory, to the high availability settings. You can run mssql-conf list to get a complete listing of commands to run, or run man mssql-conf to see the complete guide to the config binary.
Setting Configuration through Environment Variables
Using mssql-conf is great when you’re running SQL Server locally, but often times it’s not possible to execute commands directly on a database server. This is especially true in a containerized setting, like when running Docker. There, it can be helpful to set important configuration values through the environment, which can be manipulated in a container setting.
As above, we can change the configuration to make SQL Server run on a different port, port 14330. This time, we set an environment variable to make the change. Add the following to your Dockerfile before the line running SQL Server:
ENV MSSQL_TCP_PORT 14330
And then run docker build to build a new container with the different port. Make sure that you allow access on the new port, and that you restart the container with the new environment variable, and you should see SQL Server running with the new configuration on the new port.
As before, several important configuration values can be set using the environment, including data directories, high availability, and even the initial installation password. While it’s possible to use either mssl-conf or environment variables to configure SQL Server on Linux, it’s best to use mssql-conf if you can. That allows you to easily see what the existing configuration is, and change it in a central place.