Using Microsoft SQL Server (MSSQL Server) in Ubuntu

SQL Server is a relational database management system (RDBMS) developed and marketed by Microsoft. As a database server, the primary function of the SQL Server is to store and retrieve data used by other applications like MySQL/MariaDB, PostgreSQL etc.

Open a command terminal,

Import the public repository GPG keys:

sudo wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

Register the Microsoft SQL Server Ubuntu repository for SQL Server 2019:

For Ubuntu 20.04:

sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list)"

Run the following commands to install SQL Server:

sudo apt-get update
sudo apt-get install -y mssql-server


After the package installation finishes, run mssql-conf setup and follow the prompts to set the SA password and choose your edition.

sudo /opt/mssql/bin/mssql-conf setup

Once the configuration is done, verify that the service is running:

sudo systemctl status mssql-server –no-pager

If you plan to connect remotely, you might also need to open the SQL Server TCP port (default 1433) on your firewall.

sudo ufw enable

sudo ufw allow 1433/tcp


At this point, SQL Server 2019 is running on your Ubuntu machine and is ready to use!

Install the SQL Server command-line tools

To create a database, you need to connect with a tool that can run Transact-SQL statements on the SQL Server. The following steps install the SQL Server command-line tools: sqlcmd and bcp.


Use the following steps to install the mssql-tools on Ubuntu.

sudo apt install -y curl
sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -


Register the Microsoft Ubuntu repository.
 

For Ubuntu 20.04:

sudo curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

Update the sources list and run the installation command with the unixODBC developer package.

sudo apt-get update
sudo apt-get install -y mssql-tools unixodbc-dev


Optional: Add /opt/mssql-tools/bin/ to your PATH environment variable in a bash shell.


To make sqlcmd/bcp accessible from the bash shell for login sessions, modify your PATH in the ~/.bash_profile file with the following command:

sudo echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile

To make sqlcmd/bcp accessible from the bash shell for interactive/non-login sessions, modify the PATH in the ~/.bashrc file with the following command:

sudo echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc


Connect MSSQL Server

The following steps use sqlcmd to locally connect to your new SQL Server instance.

Run sqlcmd with parameters for your SQL Server name (-S), the user name (-U), and the password (-P). In this tutorial, you are connecting locally, so the server name is localhost. The user name is SA and the password is the one you provided for the SA account during setup.

Connect locally

sqlcmd -S localhost -U SA -P '<YourPassword>'

Connect remotely

sqlcmd -S 192.168.100.103 -U SA -P '<YourPassword>'

 

For GUI connection DBeaver can be used in Linux systems Install DBeaver on Debian/Ubuntu

 

https://libtechnophile.blogspot.com/2020/05/install-and-configure-dbeaver-on.html

 

Reference: 

https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-ver15

0 Komentar