Cómo instalar MariaDB en Alpine Linux

Alpine Linux es una distribución minimalista con un enfoque en la seguridad y simplicidad.

MariaDB es uno de los servidores de bases de datos más populares del mundo, creado por los desarrolladores originales de MySQL y concebido inicialmente como un reemplazo directo y mejorado de MySQL. MariaDB es rápido, escalable y robusto, con un rico ecosistema de motores de almacenamiento, complementos y otras herramientas que lo hacen versátil y flexible en diferentes escenarios. MariaDB se desarrolla como software libre bajo licencia GPL. Las últimas versiones de MariaDB también incluyen funciones GIS y JSON.

MariaDB está disponible en los repositorios oficiales de Alpine Linux por lo que podemos instalar el servidor y herramientas clientes ejecutando el siguiente comando:

Instalar

# apk add mariadb

Administrar el proceso del servidor

En esta parte aprenderemos cómo iniciar, detener o reiniciar el servicio de mariadb, para esto usaremos el sistema de inicialización OpenRC. OpenRC es el sistema de inicialización por defecto en distribuciones como Gentoo y Alpine Linux.

Comprobar estado

# rc-service mariadb status
 * status: stopped

Iniciar

# rc-service mariadb start
 * Caching service dependencies ...         [ ok ]
 * Datadir '/var/lib/mysql' is empty or invalid.
 * Run '/etc/init.d/mariadb setup' to create new database.
 * ERROR: mariadb failed to start

El error anterior nos indica que no hemos inicializado/instalado las BD por lo que debemos ejecutar el siguiente comando:

# /etc/init.d/mariadb setup
 * Creating a new MySQL database ...
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
OK
...

y ahora si podemos iniciar nuestro servidor de BD

# rc-service mariadb start
 * Starting mariadb ...
210413 22:11:45 mysqld_safe Logging to syslog.
210413 22:11:45 mysqld_safe Starting mariadbd daemon with databases from /var/lib/mysql            [ ok ]

Ahora comprobamos el estado nuevamente

# rc-service mariadb status
 * status: started

Arranque automático

Puede asegurarse de que MariaDB se iniciará automáticamente después de un reinicio del sistema ejecutando el siguiente comando:

# rc-update add mariadb default
 * service mariadb added to runlevel default

Detener el servicio

Si necesita detener el servicio de mariadb ejecute el siguiente comando:

# rc-service mariadb stop
 * Stopping mariadb ...             [ ok ]

Conectarnos al servidor de BD

Para poder conectarnos al servcidor de BD debemos instalar el paquete mariadb-client

# apk add mariadb-client

El paquete mariadb-client incluye el shell mysql por lo que podemos ejecutar:

# mysql -u root 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.5.8-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

Ahora podemos mostrar las BD con:

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.000 sec)

Mejorar la seguridad de nuestro servidor de BD:

mariadb_secure_installation es un shell script disponible en sistemas Unix, mariadb_secure_installation permite:

  • Establecer una contraseña para el usuario de root o cambiar el método de autenticación.
  • Deshabilitar acceso remoto usando el usuario root.
  • Eliminar cuentas de usuarios anónimos.
  • Eliminar la base de datos de prueba, a la que pueden acceder de forma predeterminada usuarios anónimos.
$ mariadb-secure-installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] Y
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
YouTube video

Administrar MySQL desde la línea de comandos, 3 (18)

Deja un comentario

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

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.