Cómo instalar el servidor de bases de datos MySQL 8 en CentOS 8

MySQL es un sistema de bases de datos gratuito, de código abierto y uno de los más populares en todo el mundo. Es una plataforma de gestión de bases de datos relacionales impulsada por Oracle Cloud. Utiliza el Lenguaje de Consulta Estructurado para añadir, acceder y gestionar el contenido de una base de datos. Es conocido por su probada fiabilidad, rapidez de procesamiento, facilidad y flexibilidad de uso. Hay varias características nuevas que se han añadido en MySQL 8, como el soporte de JSON, el diccionario de datos transaccional, la configuración de tiempo de ejecución persistente, el almacén de documentos, las sugerencias del optimizador, los roles SQL, las funciones CTE y de ventana, los índices invisibles y muchas más.

Nota: Antes de instalar MySQL 8, consulta ladocumentación oficial, ya que MySQL 8 tiene algunas características nuevas y cambios que hacen que algunas aplicaciones sean incompatibles con esta versión.

En este tutorial, te mostraremos cómo instalar la base de datos MySQL 8 en un servidor CentOS 8.

Requisitos previos

  • Un servidor que ejecute CentOS 8.
  • Una contraseña de root configurada en tu servidor.

Instalar MySQL 8.0 desde el repositorio de MySQL

Por defecto, MySQL 8.0 no está disponible en el repositorio por defecto de CentOS 8. Así que tendrás que instalar el repositorio comunitario de MySQL 8.0 en tu sistema. Puedes instalarlo con el siguiente comando:

rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm

Deberías ver la siguiente salida:

Retrieving https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
warning: /var/tmp/rpm-tmp.hF0m5V: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql80-community-release-el8-1  ################################# [100%]

A continuación, comprueba si el repositorio de MySQL 8.0 ha sido habilitado o no con el siguiente comando:

dnf repolist all | grep mysql | grep enabled

Deberías ver la siguiente salida:

CentOS-8 - AppStream                            3.1 MB/s | 6.5 MB     00:02    
CentOS-8 - Base                                 3.0 MB/s | 5.0 MB     00:01    
CentOS-8 - Extras                               5.3 kB/s | 2.1 kB     00:00    
MySQL 8.0 Community Server                       24 MB/s | 543 kB     00:00    
MySQL Connectors Community                      1.9 MB/s |  19 kB     00:00    
MySQL Tools Community                           677 kB/s |  62 kB     00:00    
mysql-connectors-community         MySQL Connectors Community     enabled:    42
mysql-tools-community              MySQL Tools Community          enabled:    19
mysql80-community                  MySQL 8.0 Community Server     enabled:    31

A continuación, desactiva temporalmente el repositorio de AppStream e instala la última versión de MySQL 8.0 desde el repositorio de la comunidad MySQL con el siguiente comando

dnf --disablerepo=AppStream install mysql-community-server -y

Una vez que la instalación se haya completado con éxito, puedes verificar la versión instalada de MySQL con el siguiente comando:

mysql -Version

Deberías ver la siguiente salida:

mysql  Ver 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL)

A continuación, inicia el servicio MySQL y permite que se inicie tras el reinicio del sistema con el siguiente comando:

systemctl start mysqld
systemctl enable mysqld

También puedes comprobar el estado de MySQL con el siguiente comando:

systemctl status mysqld

Deberías ver la siguiente salida:

? mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-03-05 09:37:46 EST; 12s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 3244 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 3329 (mysqld)
   Status: "Server is operational"
    Tasks: 39 (limit: 12537)
   Memory: 587.7M
   CGroup: /system.slice/mysqld.service
           ??3329 /usr/sbin/mysqld

Mar 05 09:37:01 centos8 systemd[1]: Starting MySQL Server...
Mar 05 09:37:46 centos8 systemd[1]: Started MySQL Server.

A continuación, siempre es una buena idea ejecutar el script mysql_secure_installation para habilitar algunas funciones de seguridad adicionales, como establecer una nueva contraseña de raíz de MySQL, eliminar el usuario anónimo y desactivar el inicio de sesión remoto.

En primer lugar, encuentra la contraseña raíz de MySQL por defecto utilizando el siguiente comando:

cat /var/log/mysqld.log | grep -i 'temporary password'

Salida:

2020-03-05T14:37:40.273796Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: GN2uNx-vPqwS

Anota la contraseña anterior y cámbiala con el script mysql_secure_installation.

mysql_secure_installation

Responde a todas las preguntas como se muestra a continuación:

Securing the MySQL server deployment.

Enter password for user root:   Provide your temporary MySQL root password

The existing password for the user account root has expired. Please set a new password.

New password:   Provide new root password

Re-enter new password:   Re-enter new root password
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N  Type N and Enter to continue

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!

Instalar MySQL 8.0 desde el repositorio de AppStream

También puedes instalar MySQL 8.0 desde el repositorio por defecto de AppStream en CentOS 8. Puedes instalarlo con el siguiente comando:

dnf install @mysql -y

Una vez finalizada la instalación, comprueba la versión de MySQL con el siguiente comando:

mysql -Version

Deberías ver la siguiente salida:

mysql  Ver 8.0.17 for Linux on x86_64 (Source distribution)

A continuación, inicia el servicio MySQL y permite que se inicie tras el reinicio del sistema con el siguiente comando:

systemctl start mysqld
systemctl enable mysqld

Por defecto, la contraseña de root de MySQL no está establecida en el CentoS 8. Así que tendrás que establecerla mediante el script mysql_secure_installation.

mysql_secure_installation

Responde a todas las preguntas como se muestra a continuación:

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y
Success.

All done! 

Conclusión

En la guía anterior, has aprendido a instalar MySQL 8 desde el repositorio de la comunidad de MySQL y desde el repositorio de AppStream en CentOS 8. Ahora puedes empezar a crear una nueva base de datos y usuarios de la base de datos.

También te podría gustar...