Install Microsoft SQL Server 2022 On Ubuntu 22.04

Ref: https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-ver16&tabs=ubuntu2204

1. Update and upgrade the packages on ubuntu 22.04
[codesyntax lang=”bash”]

[/codesyntax]

2. Download the public key, convert from ASCII to GPG format, and write it to the required location:
[codesyntax lang=”bash”]

[/codesyntax]

3. Manually download and register the SQL Server Ubuntu repository:
[codesyntax lang=”bash”]

[/codesyntax]

4. Run the following commands to install SQL Server:
[codesyntax lang=”bash”]

[/codesyntax]

5. After the package installation finishes, run mssql-conf setup and follow the prompts to set the sa password and choose your edition.
Just choose ‘Developer’ version. type 2. My local sa password is {my-nick-name-first-uppercase}@123
[codesyntax lang=”bash”]

[/codesyntax]

6. Once the configuration is done, verify that the service is running:
[codesyntax lang=”bash”]

[/codesyntax]

Install the SQL Server command-line tools (sqlcmd)

1. Import the public repository GPG keys.
[codesyntax lang=”bash”]

[/codesyntax]

2. Register the Microsoft Ubuntu repository. For Ubuntu 22.04, use the following command:
[codesyntax lang=”bash”]

[/codesyntax]

3. Update the sources list and run the installation command with the unixODBC developer package.
[codesyntax lang=”bash”]

[/codesyntax]

To update to the latest version of mssql-tools, run the following commands:
[codesyntax lang=”bash”]

[/codesyntax]

4. Add /opt/mssql-tools18/bin/ to your PATH environment variable in a bash shell.

To make sqlcmd and bcp accessible from the bash shell for login sessions, modify your PATH in the ~/.bash_profile file with the following command:
[codesyntax lang=”bash”]

[/codesyntax]

5. Test sqlcmd with ‘sqlcmd -?’
[codesyntax lang=”bash”]

[/codesyntax]

Connect locally. I tried to use : sqlcmd -S localhost -U sa -P your_password
but it showed up this error
[codesyntax lang=”bash”]

[/codesyntax]

it turned out I need to add -C parameter at the end like this
[codesyntax lang=”bash”]

[/codesyntax]

Create a new database

For example create a new database TestDB from sqlcmd
[codesyntax lang=”bash”]

[/codesyntax]

Create a new table dbo.Inventory and Insert data
[codesyntax lang=”bash”]

[/codesyntax]

Install DBeaver (https://dbeaver.io/)
This is Database GUI for many databases including MS SQL Server

Download it https://dbeaver.io/download/
I used Ubuntu PPA
[codesyntax lang=”bash”]

[/codesyntax]

Open DBeaver CE and select to the MS SQL Server

Connect to the MS SQL Server but it needs to use JDBC driver. Install it directly from the DBeaver

If everything is okay, it’ll look like this

on the DBeaver GUI you can add a new row. for example add a new row
ID: 3
Name: Apple
Quantity: 158
Then save

on the sqlcmd should reflect the changes
[codesyntax lang=”bash”]

[/codesyntax]

Leave a Reply

Your email address will not be published. Required fields are marked *