GNU/Linux >> Tutoriels Linux >  >> Cent OS

Comment installer MySQL 8.0 sur CentOS 8 / RHEL 8

MySQL est un logiciel de système de gestion de base de données gratuit le plus couramment utilisé dans les applications à trois niveaux pour stocker et récupérer des enregistrements et des informations.

MySQL a été initialement développé par MYSQL AB, maintenant propriété d'Oracle Corporation. C'était la principale application de base de données sous Linux jusqu'à ce que MariaDB, un fork de MySQL, entre en scène.

Dans cet article, nous verrons comment installer MySQL 8.0 sur CentOS 8 / RHEL 8.

Les étapes mentionnées dans cet article ne fonctionneront que si vous avez activé l'abonnement sur RHEL 8 ou configuré le référentiel yum local sur votre système.

Installer MySQL 8.0 sur CentOS 8 / RHEL 8

MySQL 8.0 est disponible pour CentOS 8 / RHEL 8 à partir du référentiel OS AppStream et du référentiel MySQL Dev Community. 1. Installez MySQL 8.0 depuis MySQL Dev Community 2. Installez MySQL 8.0 depuis AppStream

1. Installez MySQL 8.0 à partir de la communauté de développement MySQL

Ajoutez le dépôt officiel de MySQL pour installer le serveur communautaire MySQL.

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

Assurez-vous que le référentiel MySQL a été ajouté et activé à l'aide de la commande suivante.

dnf repolist all | grep mysql | grep enabled

Sortie :

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

Utilisez la commande dnf dans CentOS/RHEL pour installer la dernière version stable de MySQL. Désactivez temporairement le référentiel AppStream pour installer MySQL à partir de 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

Sortie :

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. Installez MySQL 8.0 depuis AppStream

MySQL est désormais disponible via le flux d'applications (Red Hat Enterprise Linux 8 pour x86_64 - AppStream (RPM)) pour RHEL 8 et CentOS 8. Ainsi, vous n'avez pas besoin d'ajouter un référentiel officiel de MySQL pour installer le serveur MySQL sur RHEL 8.

Vérifiez si le référentiel AppStream est activé sur RHEL 8 à l'aide de la commande suivante.

subscription-manager repos --list-enabled

Sortie :

+----------------------------------------------------------+
    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

Utilisez la commande dnf pour installer la dernière version de MySQL.

dnf install -y @mysql

Sortie :

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!

Gérer le service de serveur MySQL

Après l'installation de MySQL, démarrez le service du serveur MySQL à l'aide de la commande suivante.

systemctl start mysqld

Activer le serveur MySQL au démarrage du système.

systemctl enable mysqld

Vérifiez que le serveur MySQL est démarré à l'aide de la commande suivante.

systemctl status mysqld

Sortie :

 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.

Serveur MySQL sécurisé

Installation de MySQL à partir de la communauté de développement MySQL

Dans CentOS 8 / RHEL 8, le mot de passe racine MySQL initial se trouve dans /var/log/mysqld.log. Vous pouvez utiliser la commande ci-dessous pour extraire le mot de passe du fichier journal.

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

Sortie :

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

Maintenant, vous devez exécuter mysql_secure_installation pour sécuriser votre installation MySQL. Cette commande s'occupe de définir le mot de passe root, de supprimer les utilisateurs anonymes, d'interdire la connexion root à distance, etc.

mysql_secure_installation

Sortie :

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!

Installation de MySQL à partir d'AppStream

Dans CentOS 8/RHEL 8, aucun mot de passe n'est défini pour l'utilisateur racine MySQL . Nous allons donc exécuter mysql_secure_installation pour sécuriser votre installation MySQL en définissant le mot de passe root, en supprimant les utilisateurs anonymes, en interdisant la connexion root à distance, etc.

mysql_secure_installation

Sortie :

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!

Travailler avec le serveur MySQL

Connectez-vous au serveur MySQL en tant qu'utilisateur racine MySQL.

mysql -u root -p

Sortie :

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>

Installer phpMyAdmin

Si vous débutez avec MySQL et que vous avez moins de connaissances sur la ligne de commande MySQL, envisagez d'installer phpMyAdmin, un outil de gestion Web open source pour gérer les bases de données MySQL et MariaDB.

LIRE : Comment installer phpMyAdmin avec Apache sur CentOS 8 / RHEL 8

LIRE : Comment installer phpMyAdmin avec Nginx sur CentOS 8 / RHEL 8

Notes pour MySQL 8.0 installé à partir du référentiel MySQL Dev Community :

MySQL 8.0 utilise un mécanisme caching_sha2_password pour l'authentification qui empêche les applications héritées d'accéder aux bases de données, y compris phpMyAdmin pour le moment. En termes simples, vous ne serez pas connecté à phpMyAdmin à moins que nous ne désactivions ce nouveau mécanisme de mot de passe.

Vous pouvez désactiver globalement le nouveau mécanisme de mot de passe en plaçant default-authentication-plugin=mysql_native_password dans /etc/my.cnf (les utilisateurs créés après ce changement auront le mécanisme d'authentification mysql_native_password) ou vous pouvez revenir à l'ancienne authentification native (mysql_native_password) pour les utilisateurs (Ex :root) en exécutant ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '' ; commande dans le terminal MySQL.

Conclusion

Dans cet article, vous avez appris comment installer MySQL 8.0 sur CentOS 8 / RHEL 8. Veuillez partager vos commentaires dans la section des commentaires.


Cent OS
  1. Comment installer MySQL sur CentOS 7

  2. Comment installer MySQL sur CentOS 8

  3. Comment installer phpMyAdmin sur RHEL 8 / CentOS 8

  4. Comment installer MySQL 8.0 sur CentOS/RHEL 8

  5. Comment installer MySQL 5.6 sur CentOS 6.x

Comment installer mongodb sur RHEL 8 / CentOS 8

Comment installer maven sur RHEL 8 / CentOS 8

Comment installer cpan sur RHEL 8 / CentOS 8

Comment installer ruby ​​sur RHEL 8 / CentOS 8

Comment installer MySQL sur CentOS 8

Comment installer Cacti sur CentOS 6 / RHEL 6