# SQL Server

Instalar SQL Server en Ubuntu 18.04

{% embed url="https://medium.com/@mad.gfender/instalar-sql-server-en-ubuntu-18-04-2e223e9bfc8f" %}



Actualizar

```
sudo apt-get update
```

Ejecutar

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



Registrar las llaves

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



Instalar

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

Ejecutar la configuración

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

Verificar la instalaciòn

```
systemctl status mssql-server
```

Nos debe mostrar en verde que esta activo.



Detener SQL

Fuente

{% embed url="https://www.mssqltips.com/sqlservertip/4727/how-to-stop-start-enable-and-disable-sql-server-services-on-linux/" %}



```
sudo systemctl stop mssql-server
```

Iniciar SQL Server

```
sudo systemctl start mssql-server
```

Ver el estatus SQL Server

```
systemctl status mssql-server
```

Detener y desabilitar servicios de SQL Server

```
sudo systemctl stop mssql-server

sudo systemctl disable mssql-server
```

Habilitar los servicios de SQL Server al inicio

```
sudo systemctl enable mssql-server

sudo systemctl start mssql-server
```





### Script para Iniciar/Detener SQL Server

![](https://547521780-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lc1Wg6HsWAzyOSRs0Cb%2F-LvkVObHRDPAB2MHckMB%2F-Lvk_3T_qYPMre2Fqk7T%2Fsqlserver.png?alt=media\&token=f8e7247e-8f84-43a9-81dd-1c798ca3a352)

```bash
#!/bin/bash
DIA=`date +"%Y_%m_%d"`
HORA=`date +"_%H_%M"`
backup="b"
restore="r"
menu = "b"
continue="si"
while [ "$continue" == "si" ]
do
  clear
#
echo "--------------------------------------------"
echo "   SQL SERVER-"
echo "--------------------------------------------"
echo "   1. Ver Status"
echo "   2. Iniciar"
echo "   3. Detener "
echo "   4. Salir"
echo "           "
echo "      Ingrese numero de opcion__"

read menu
if [ "$menu" == "1" ] ; then
	#realiza respaldos de MongoDB
        echo "-----------------------------------------------"
	echo 'Status de SQLServer'
	echo "-----------------------------------------------"
	systemctl status mssql-server


        echo "presione una tecla"
        read tecla
	
else
      if [ "$menu" == "2" ]; then

		echo "-----------------------------------------------"
		echo 'Iniciando SQL Sever'
		echo "-----------------------------------------------"
		sudo systemctl start mssql-server

		echo "-----------------------------------------------"
		echo "SQL Server Iniciado"
		echo "-----------------------------------------------"
                echo "presione una tecla"
                read tecla
	else
                 if [ "$menu" == "3" ] ; then
                    echo "-----------------------------------------------"
          	    echo "Deteniendo SQL Server"
		    echo "-----------------------------------------------"
                    sudo systemctl stop mssql-server
                 else
                     if [ "$menu" == "4" ] ; then
                      continue="no"
                       echo "-----------------------------------------------"
                       echo "Saliendo"
		       echo "-----------------------------------------------"   
                                     
                     else
	                echo "Opcion invalida (1/2/3/4)"
                        echo "presione una tecla"
                        read tecla
                    fi
                fi
 
        fi
fi
done
```



### Cliente para SQLServer en Linux, puedes verlo en el&#x20;

{% embed url="https://app.gitbook.com/@avbravo-2/s/docker/sql-server/cliente" %}

