Saltar al contenido
Menú
El blog de Kañaz
  • Inicio
  • Acerca de
  • Github
  • Youtube
  • LinkedIn
  • Twitter
El blog de Kañaz

Instalación de SQL Server en Ubuntu 20.04

Publicada el 12 febrero, 202112 febrero, 2021
Twittear

SQL Server es a pesar de la enorme oferta actual de motores de bases de datos un producto de gran utilidad que en 2017 dió el salto a Linux. Con .NET Core ya disponible también para muchas distribuciones es ahora posible crear muchas aplicaciones con toda la tecnología de Microsoft, principalmente APIs completamente desde Linux. En este artículo cubriré cómo instalar SQL Server en Ubuntu.

El único prerequisito que requieres es conocer la versión de Ubuntu que tienes instalada.

Preparando todo tu ambiente

Comienza como ya debes estar acostumbrado por actualizar tu sistema.

sudo apt-get update
sudo apt-get -y upgrade

sudo apt-get update sudo apt-get -y upgrade

Quizá sea necesario reiniciar tu sistema para garantizar que todo funciona bien.

sudo reboot

sudo reboot

El siguiente paso es agregar la llave GPC en el sistema para confiar en los repositorios apt de MS SQL.

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

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

Agrega el repositorio APT de SQL Server 2019 a tu sistema de Ubuntu dependiendo de su versión, para el caso de Ubuntu 20.04 y 18.04 (cubro estas dos versiones únicamente por tratarse de las versiones LTS).

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

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

Instalando SQL Server

El comando más importante, el de la instalación de SQL Server.

sudo apt update
sudo apt install mssql-server

sudo apt update sudo apt install mssql-server

Naturalmente, como en cada paquete apt, deberás aceptar la instalación. Para obtener un resultado similar al siguiente.

....
Unpacking mssql-server (15.0.4033.1-2) ...
Setting up libdw1:amd64 (0.176-1.1build1) ...
Setting up gawk (1:5.0.1+dfsg-1) ...
Setting up libsasl2-modules:amd64 (2.1.27+dfsg-2) ...
Setting up libpython2.7-stdlib:amd64 (2.7.18~rc1-2) ...
Setting up libbabeltrace1:amd64 (1.5.8-1build1) ...
Setting up libc++abi1-10:amd64 (1:10.0.0-4ubuntu1) ...
Setting up libsss-nss-idmap0 (2.2.3-3) ...
Setting up libsasl2-modules-gssapi-mit:amd64 (2.1.27+dfsg-2) ...
Setting up libc++1-10:amd64 (1:10.0.0-4ubuntu1) ...
Setting up python2.7 (2.7.18~rc1-2) ...
Setting up libpython2-stdlib:amd64 (2.7.17-2ubuntu4) ...
Setting up python2 (2.7.17-2ubuntu4) ...
Setting up gdb (9.1-0ubuntu1) ...
Setting up python-is-python2 (2.7.17-4) ...
Setting up libc++1:amd64 (1:10.0-50~exp1) ...
Setting up mssql-server (15.0.4033.1-2) ...
debconf: unable to initialize frontend: Dialog
debconf: (Dialog frontend requires a screen at least 13 lines tall and 31 columns wide.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
 
+--------------------------------------------------------------+
Please run 'sudo /opt/mssql/bin/mssql-conf setup'
to complete the setup of Microsoft SQL Server
+--------------------------------------------------------------+
 
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for libc-bin (2.31-0ubuntu9) ...

.... Unpacking mssql-server (15.0.4033.1-2) ... Setting up libdw1:amd64 (0.176-1.1build1) ... Setting up gawk (1:5.0.1+dfsg-1) ... Setting up libsasl2-modules:amd64 (2.1.27+dfsg-2) ... Setting up libpython2.7-stdlib:amd64 (2.7.18~rc1-2) ... Setting up libbabeltrace1:amd64 (1.5.8-1build1) ... Setting up libc++abi1-10:amd64 (1:10.0.0-4ubuntu1) ... Setting up libsss-nss-idmap0 (2.2.3-3) ... Setting up libsasl2-modules-gssapi-mit:amd64 (2.1.27+dfsg-2) ... Setting up libc++1-10:amd64 (1:10.0.0-4ubuntu1) ... Setting up python2.7 (2.7.18~rc1-2) ... Setting up libpython2-stdlib:amd64 (2.7.17-2ubuntu4) ... Setting up python2 (2.7.17-2ubuntu4) ... Setting up gdb (9.1-0ubuntu1) ... Setting up python-is-python2 (2.7.17-4) ... Setting up libc++1:amd64 (1:10.0-50~exp1) ... Setting up mssql-server (15.0.4033.1-2) ... debconf: unable to initialize frontend: Dialog debconf: (Dialog frontend requires a screen at least 13 lines tall and 31 columns wide.) debconf: falling back to frontend: Readline debconf: unable to initialize frontend: Readline debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.) debconf: falling back to frontend: Teletype +--------------------------------------------------------------+ Please run 'sudo /opt/mssql/bin/mssql-conf setup' to complete the setup of Microsoft SQL Server +--------------------------------------------------------------+ Processing triggers for man-db (2.9.1-1) ... Processing triggers for mime-support (3.64ubuntu1) ... Processing triggers for libc-bin (2.31-0ubuntu9) ...

Configurando SQL Server

Después de la instalación, lo que sigue es establecer la configuración de SQL, de hecho al final de la instalación te dicen exactamente que comando escribir para esto.

sudo /opt/mssql/bin/mssql-conf setup
Choose an edition of SQL Server:
  1) Evaluation (free, no production use rights, 180-day limit)
  2) Developer (free, no production use rights)
  3) Express (free)
  4) Web (PAID)
  5) Standard (PAID)
  6) Enterprise (PAID)
  7) Enterprise Core (PAID)
  8) I bought a license through a retail sales channel and have a product key to enter.
 
Details about editions can be found at
https://go.microsoft.com/fwlink/?LinkId=852748&clcid=0x409
 
Use of PAID editions of this software requires separate licensing through a
Microsoft Volume Licensing program.
By choosing a PAID edition, you are verifying that you have the appropriate
number of licenses in place to install and run this software.
 
Enter your edition(1-8): 2
The license terms for this product can be found in
/usr/share/doc/mssql-server or downloaded from:
https://go.microsoft.com/fwlink/?LinkId=855862&clcid=0x409
 
The privacy statement can be viewed at:
https://go.microsoft.com/fwlink/?LinkId=853010&clcid=0x409
 
Do you accept the license terms? [Yes/No]:Yes
 
Enter the SQL Server system administrator password:  <SetStrongNewPassword>
Confirm the SQL Server system administrator password: <ConfirmStrongPassword>
Configuring SQL Server...
 
ForceFlush is enabled for this instance. 
ForceFlush feature is enabled for log durability.
Created symlink /etc/systemd/system/multi-user.target.wants/mssql-server.service → /lib/systemd/system/mssql-server.service.
Setup has completed successfully. SQL Server is now starting.

sudo /opt/mssql/bin/mssql-conf setup Choose an edition of SQL Server: 1) Evaluation (free, no production use rights, 180-day limit) 2) Developer (free, no production use rights) 3) Express (free) 4) Web (PAID) 5) Standard (PAID) 6) Enterprise (PAID) 7) Enterprise Core (PAID) 8) I bought a license through a retail sales channel and have a product key to enter. Details about editions can be found at https://go.microsoft.com/fwlink/?LinkId=852748&clcid=0x409 Use of PAID editions of this software requires separate licensing through a Microsoft Volume Licensing program. By choosing a PAID edition, you are verifying that you have the appropriate number of licenses in place to install and run this software. Enter your edition(1-8): 2 The license terms for this product can be found in /usr/share/doc/mssql-server or downloaded from: https://go.microsoft.com/fwlink/?LinkId=855862&clcid=0x409 The privacy statement can be viewed at: https://go.microsoft.com/fwlink/?LinkId=853010&clcid=0x409 Do you accept the license terms? [Yes/No]:Yes Enter the SQL Server system administrator password: <SetStrongNewPassword> Confirm the SQL Server system administrator password: <ConfirmStrongPassword> Configuring SQL Server... ForceFlush is enabled for this instance. ForceFlush feature is enabled for log durability. Created symlink /etc/systemd/system/multi-user.target.wants/mssql-server.service → /lib/systemd/system/mssql-server.service. Setup has completed successfully. SQL Server is now starting.

El servicio de MS SQL debería ya haber comenzado. Para ello escribe el siguiente comando.

systemctl status mssql-server.service

systemctl status mssql-server.service

Para tener un resultado como esto.

Hasta ahora, tu servicio ya está accesible pero lo que sigue es instalar las herramientas de MS SQL y un plugin llamado unixODBC.

Ubuntu 20.04

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/19.10/prod.list > /etc/apt/sources.list.d/mssql-release.list
sudo apt update 
sudo ACCEPT_EULA=Y apt install mssql-tools unixodbc-dev

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - curl https://packages.microsoft.com/config/ubuntu/19.10/prod.list > /etc/apt/sources.list.d/mssql-release.list sudo apt update sudo ACCEPT_EULA=Y apt install mssql-tools unixodbc-dev

Ubuntu 18.04

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt update 
sudo sudo ACCEPT_EULA=Y apt install mssql-tools unixodbc-dev

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list sudo apt update sudo sudo ACCEPT_EULA=Y apt install mssql-tools unixodbc-dev

Continua por agregar la ruta de estas herramientas a una variable de ambiente para poder hacer accesible a la herramienta sqlcmd/bcp con el siguiente comando.

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

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

Usa MS SQL desde tu terminal

Con toda la configuración ya lista, es momento de establecer la conexión que necesitamos. Aprovecha para consultar tus bases de datos y también para crear una base de datos con la sesión ya iniciada.

¡Perfecto! Ya puedes comenzar a trabajar con MS SQL sin ningún problema en tu equipo, te recomiendo que ya que hayas terminado con esto, quizá quieras revisar como configurar tu servidor para aceptar conexiones remotas. De esta manera podrías conectarte desde SQL Management Studio en Windows a tu nuevo servidor.

1 comentario en «Instalación de SQL Server en Ubuntu 20.04»

  1. Pingback: Cómo conectarte de manera remota a SQL Server en Ubuntu – El blog de Kañaz

Deja una respuesta Cancelar la respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Busca en este sitio

MI perfil de Github

Github profile

Sígueme en Twitter

Seguir a @aminespinoza
©2023 El blog de Kañaz | Funciona con SuperbThemes y WordPress