GNU/Linux >> Tutoriales Linux >  >> Cent OS

Cómo instalar MySQL 8.0 en CentOS 8 / RHEL 8

MySQL es un software de sistema de administración de base de datos gratuito que se usa más comúnmente en aplicaciones de tres niveles para almacenar y recuperar registros e información.

MySQL fue desarrollado inicialmente por MYSQL AB, ahora propiedad de Oracle Corporation. Era la principal aplicación de base de datos en Linux hasta que apareció MariaDB, una bifurcación de MySQL.

En este artículo, veremos los pasos para instalar MySQL 8.0 en CentOS 8/RHEL 8.

Los pasos mencionados en este artículo solo funcionarán si ha habilitado la suscripción en RHEL 8 o ha configurado el repositorio local de yum en su sistema.

Instalar MySQL 8.0 en CentOS 8/RHEL 8

MySQL 8.0 está disponible para CentOS 8/RHEL 8 tanto en el repositorio OS AppStream como en el repositorio MySQL Dev Community. 1. Instale MySQL 8.0 desde MySQL Dev Community 2. Instale MySQL 8.0 desde AppStream

1. Instale MySQL 8.0 desde MySQL Dev Community

Agregue el repositorio oficial de MySQL para instalar el servidor de la comunidad MySQL.

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

Asegúrese de que el repositorio de MySQL se haya agregado y habilitado con el siguiente comando.

dnf repolist all | grep mysql | grep enabled

Salida:

mysql-connectors-community         MySQL Connectors Community           enabled
mysql-tools-community              MySQL Tools Community                enabled
mysql80-community                  MySQL 8.0 Community Server           enabled

Utilice el comando dnf en CentOS/RHEL para instalar la última versión estable de MySQL. Deshabilite el repositorio de AppStream temporalmente para instalar MySQL desde MySQL Dev Community.

### CentOS 8 ###

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

### RHEL 8 ###

dnf install -y --disablerepo=rhel-8-for-x86_64-appstream-rpms mysql-community-server

Salida:

Dependencies resolved.
========================================================================================================================================================================
 Package                                             Architecture                Version                                   Repository                              Size
========================================================================================================================================================================
Installing:
 mysql-community-server                              x86_64                      8.0.25-1.el8                              mysql80-community                       53 M
Installing dependencies:
 mysql-community-client                              x86_64                      8.0.25-1.el8                              mysql80-community                       13 M
 mysql-community-client-plugins                      x86_64                      8.0.25-1.el8                              mysql80-community                       98 k
 mysql-community-common                              x86_64                      8.0.25-1.el8                              mysql80-community                      618 k
 mysql-community-libs                                x86_64                      8.0.25-1.el8                              mysql80-community                      1.4 M
 perl-Carp                                           noarch                      1.42-396.el8                              baseos                                  29 k
.     .     .
.     .     .
(36/37): mysql-community-client-8.0.25-1.el8.x86_64.rpm                                                                                 2.3 MB/s |  13 MB     00:05
(37/37): mysql-community-server-8.0.25-1.el8.x86_64.rpm                                                                                 5.0 MB/s |  53 MB     00:10
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                   4.4 MB/s |  79 MB     00:17
warning: /var/cache/dnf/mysql80-community-b1f1ed5ba88ce0f8/packages/mysql-community-client-8.0.25-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
MySQL 8.0 Community Server                                                                                                               27 MB/s |  27 kB     00:00
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <[email protected]>"
 Fingerprint: A4A9 4068 76FC BD3C 4567 70C8 8C71 8D3B 5072 E1F5
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                1/1
  Installing       : perl-Pod-Escapes-1:1.07-395.el8.noarch                                                                                                        1/37
.     .     .
.     .     .
  perl-Term-Cap-1.17-395.el8.noarch                   perl-Text-ParseWords-3.30-395.el8.noarch                    perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch
  perl-Time-Local-1:1.280-1.el8.noarch                perl-Unicode-Normalize-1.25-396.el8.x86_64                  perl-constant-1.33-396.el8.noarch
  perl-interpreter-4:5.26.3-419.el8.x86_64            perl-libs-4:5.26.3-419.el8.x86_64                           perl-macros-4:5.26.3-419.el8.x86_64
  perl-parent-1:0.237-1.el8.noarch                    perl-podlators-4.11-1.el8.noarch                            perl-threads-1:2.21-2.el8.x86_64
  perl-threads-shared-1.58-2.el8.x86_64

Complete!

2. Instale MySQL 8.0 desde AppStream

MySQL ahora está disponible a través de Application Stream (Red Hat Enterprise Linux 8 para x86_64 – AppStream (RPM)) para RHEL 8 y CentOS 8. Por lo tanto, no necesitará agregar un repositorio oficial de MySQL para instalar el servidor MySQL en RHEL 8.

Compruebe si el repositorio de AppStream está habilitado en RHEL 8 con el siguiente comando.

subscription-manager repos --list-enabled

Salida:

+----------------------------------------------------------+
    Available Repositories in /etc/yum.repos.d/redhat.repo
+----------------------------------------------------------+
Repo ID:   rhel-8-for-x86_64-baseos-rpms
Repo Name: Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)
Repo URL:  https://cdn.redhat.com/content/dist/rhel8/$releasever/x86_64/baseos/os
Enabled:   1

Repo ID:   rhel-8-for-x86_64-appstream-rpms
Repo Name: Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)
Repo URL:  https://cdn.redhat.com/content/dist/rhel8/$releasever/x86_64/appstream/os
Enabled:   1

Use el comando dnf para instalar la última versión de MySQL.

dnf install -y @mysql

Salida:

Last metadata expiration check: 0:01:25 ago on Fri 11 Oct 2019 03:35:47 PM UTC.
Dependencies resolved.
===================================================================================================================
 Package                            Arch         Version                                     Repository       Size
===================================================================================================================
Installing group/module packages:
 mysql-server                       x86_64       8.0.13-1.module_el8.0.0+41+ca30bab6         AppStream        25 M
Installing dependencies:
 mariadb-connector-c-config         noarch       3.0.7-1.el8                                 AppStream        13 k
 mecab                              x86_64       0.996-1.module_el8.0.0+41+ca30bab6.9        AppStream       397 k
 mysql                              x86_64       8.0.13-1.module_el8.0.0+41+ca30bab6         AppStream       9.2 M
 mysql-common                       x86_64       8.0.13-1.module_el8.0.0+41+ca30bab6         AppStream       142 k
 mysql-errmsg                       x86_64       8.0.13-1.module_el8.0.0+41+ca30bab6         AppStream       523 k
 perl-Digest                        noarch       1.17-395.el8                                AppStream        27 k
 perl-Digest-MD5                    x86_64       2.55-396.el8                                AppStream        37 k
 perl-Net-SSLeay                    x86_64       1.85-6.el8                                  AppStream       358 k
 perl-URI                           noarch       1.73-3.el8                                  AppStream       116 k
.      .      .
.      .      .
Enabling module streams:
 mysql                                           8.0                                                              

Transaction Summary
===================================================================================================================
Install  51 Packages

Total download size: 48 M
Installed size: 278 M
Downloading Packages:
(1/51): mariadb-connector-c-config-3.0.7-1.el8.noarch.rpm                           12 kB/s |  13 kB     00:01    
(2/51): mysql-common-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64.rpm                1.3 MB/s | 142 kB     00:00    
(3/51): mecab-0.996-1.module_el8.0.0+41+ca30bab6.9.x86_64.rpm                      328 kB/s | 397 kB     00:01    
(4/51): mysql-errmsg-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64.rpm                5.7 MB/s | 523 kB     00:00    
(5/51): perl-Digest-1.17-395.el8.noarch.rpm                                        530 kB/s |  27 kB     00:00    
(6/51): perl-Digest-MD5-2.55-396.el8.x86_64.rpm                                    959 kB/s |  37 kB     00:00    
(7/51): mysql-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64.rpm                       6.3 MB/s | 9.2 MB     00:01    
.      .      .
.      .      .
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                           1/1 
  Installing       : perl-Exporter-5.72-396.el8.noarch                                                        1/51 
  Installing       : perl-libs-4:5.26.3-416.el8.x86_64                                                        2/51 
  Installing       : perl-Carp-1.42-396.el8.noarch                                                            3/51 
  Installing       : perl-Scalar-List-Utils-3:1.49-2.el8.x86_64                                               4/51 
  Installing       : perl-parent-1:0.237-1.el8.noarch                                                         5/51 
.      .      .
.      .      .
Installed:
  mysql-server-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64  perl-IO-Socket-IP-0.39-5.el8.noarch                     
  perl-IO-Socket-SSL-2.060-2.el8.noarch                    perl-Mozilla-CA-20160104-7.el8.noarch                   
  mariadb-connector-c-config-3.0.7-1.el8.noarch            mecab-0.996-1.module_el8.0.0+41+ca30bab6.9.x86_64       
  mysql-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64         mysql-common-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64 
  mysql-errmsg-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64  perl-Digest-1.17-395.el8.noarch                         
  perl-Digest-MD5-2.55-396.el8.x86_64                      perl-Net-SSLeay-1.85-6.el8.x86_64                       
  perl-URI-1.73-3.el8.noarch                               perl-libnet-3.11-3.el8.noarch                           
  protobuf-lite-3.5.0-7.el8.x86_64                         libaio-0.3.110-12.el8.x86_64                            
  numactl-libs-2.0.12-2.el8.x86_64                         perl-Carp-1.42-396.el8.noarch                           
  perl-Data-Dumper-2.167-399.el8.x86_64                    perl-Encode-4:2.97-3.el8.x86_64                         
  perl-Errno-1.28-416.el8.x86_64                           perl-Exporter-5.72-396.el8.noarch                       
  perl-File-Path-2.15-2.el8.noarch                         perl-File-Temp-0.230.600-1.el8.noarch                   
  perl-Getopt-Long-1:2.50-4.el8.noarch                     perl-HTTP-Tiny-0.074-1.el8.noarch                       
  perl-IO-1.38-416.el8.x86_64                              perl-MIME-Base64-3.15-396.el8.x86_64                    
  perl-PathTools-3.74-1.el8.x86_64                         perl-Pod-Escapes-1:1.07-395.el8.noarch                  
  perl-Pod-Perldoc-3.28-396.el8.noarch                     perl-Pod-Simple-1:3.35-395.el8.noarch                   
  perl-Pod-Usage-4:1.69-395.el8.noarch                     perl-Scalar-List-Utils-3:1.49-2.el8.x86_64              
  perl-Socket-4:2.027-2.el8.x86_64                         perl-Storable-1:3.11-3.el8.x86_64                       
  perl-Term-ANSIColor-4.06-396.el8.noarch                  perl-Term-Cap-1.17-395.el8.noarch                       
  perl-Text-ParseWords-3.30-395.el8.noarch                 perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch            
  perl-Time-Local-1:1.280-1.el8.noarch                     perl-Unicode-Normalize-1.25-396.el8.x86_64              
  perl-constant-1.33-396.el8.noarch                        perl-interpreter-4:5.26.3-416.el8.x86_64                
  perl-libs-4:5.26.3-416.el8.x86_64                        perl-macros-4:5.26.3-416.el8.x86_64                     
  perl-parent-1:0.237-1.el8.noarch                         perl-podlators-4.11-1.el8.noarch                        
  perl-threads-1:2.21-2.el8.x86_64                         perl-threads-shared-1.58-2.el8.x86_64                   
  policycoreutils-python-utils-2.8-16.1.el8.noarch        

Complete!

Administrar el servicio del servidor MySQL

Después de la instalación de MySQL, inicie el servicio del servidor MySQL usando el siguiente comando.

systemctl start mysqld

Habilite el servidor MySQL al iniciar el sistema.

systemctl enable mysqld

Verifique que el servidor MySQL se inicie con el siguiente comando.

systemctl status mysqld

Salida:

 mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2021-07-02 00:08:12 EDT; 11s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 3794 (mysqld)
   Status: "Server is operational"
    Tasks: 38 (limit: 23664)
   Memory: 442.0M
   CGroup: /system.slice/mysqld.service
           └─3794 /usr/sbin/mysqld

Jul 02 00:08:01 rocky8.itzgeek.local systemd[1]: Starting MySQL Server...
Jul 02 00:08:12 rocky8.itzgeek.local systemd[1]: Started MySQL Server.

Servidor MySQL seguro

MySQL instalado desde la comunidad de desarrolladores de MySQL

En CentOS 8/RHEL 8, la contraseña raíz inicial de MySQL se puede encontrar en /var/log/mysqld.log. Puede usar el siguiente comando para tomar la contraseña del archivo de registro.

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

Salida:

2021-07-02T04:08:05.488758Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: PlrS,Tw&d9q2

Ahora, debe ejecutar mysql_secure_installation para asegurar su instalación de MySQL. Este comando se encarga de establecer la contraseña de root, eliminar usuarios anónimos, prohibir el inicio de sesión de root de forma remota, etc.

mysql_secure_installation

Salida:

Securing the MySQL server deployment.

Enter password for user root:   << Enter the temporary password you got from the previous step

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

New password:   << Enter 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 as we have already set root password

 ... 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  << Remove anonymous user
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  << Disallow root login remotely
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  << Remove test database
 - 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  << Reload privilege tables
Success.

All done!

MySQL instalado desde AppStream

En CentOS 8/RHEL 8, no se establece ninguna contraseña para el usuario root de MySQL . Por lo tanto, ejecutaremos mysql_secure_installation para asegurar su instalación de MySQL configurando la contraseña de root, eliminando usuarios anónimos, no permitiendo el inicio de sesión de root de forma remota, etc.

mysql_secure_installation

Salida:

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    << Type Y to use VALIDATE PASSWORD COMPONENT to check strength of passwords

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: 1    << Choose the Level of Strongness
Please set the password for root here.

New password:    << Enter Root Password

Re-enter new password:    << Re-enter Root 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    << Press Y to set password
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    << Press Y to Remove Anonymous User
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    << Press Y to Disallow Remote Root Login
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    << Press Y to Remove test database
 - 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    << Press Y to Reload Privilege
Success.

All done!

Trabajar con el servidor MySQL

Inicie sesión en el servidor MySQL como usuario root de MySQL.

mysql -u root -p

Salida:

Enter password:    << Enter MySQL Root Password
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.13 Source distribution

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>

Instalar phpMyAdmin

Si es un novato en MySQL y tiene menos conocimiento de la línea de comandos de MySQL, considere instalar phpMyAdmin, una herramienta de administración basada en web de código abierto para administrar bases de datos MySQL y MariaDB.

LEER: Cómo instalar phpMyAdmin con Apache en CentOS 8 / RHEL 8

LEER: Cómo instalar phpMyAdmin con Nginx en CentOS 8 / RHEL 8

Notas para MySQL 8.0 instaladas desde el repositorio de MySQL Dev Community:

MySQL 8.0 utiliza un mecanismo caching_sha2_password para la autenticación que impide que las aplicaciones heredadas accedan a las bases de datos, incluido phpMyAdmin en este momento. En términos simples, no iniciará sesión en phpMyAdmin a menos que deshabilitemos este nuevo mecanismo de contraseña.

Puede deshabilitar globalmente el nuevo mecanismo de contraseña colocando default-authentication-plugin=mysql_native_password en /etc/my.cnf (los usuarios creados después de este cambio tendrán el mecanismo de autenticación mysql_native_password) o puede volver a la autenticación nativa anterior (mysql_native_password) para usuarios individuales. usuarios (Ej:root) ejecutando ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''; comando en la terminal de MySQL.

Conclusión

En este artículo, ha aprendido a instalar MySQL 8.0 en CentOS 8/RHEL 8. Comparta sus comentarios en la sección de comentarios.


Cent OS
  1. Cómo instalar MySQL en CentOS 7

  2. Cómo instalar MySQL en CentOS 8

  3. Cómo instalar phpMyAdmin en RHEL 8 / CentOS 8

  4. Cómo instalar MySQL 8.0 en CentOS/RHEL 8

  5. Cómo instalar MySQL 5.6 en CentOS 6.x

Cómo instalar mongodb en RHEL 8 / CentOS 8

Cómo instalar maven en RHEL 8 / CentOS 8

Cómo instalar cpan en RHEL 8 / CentOS 8

Cómo instalar ruby ​​en RHEL 8 / CentOS 8

Cómo instalar MySQL en CentOS 8

Cómo instalar cactus en CentOS 6 / RHEL 6