MySQL est un système de gestion de base de données gratuit et open source, couramment utilisé dans les applications Web 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 pour le système d'exploitation Linux jusqu'à ce que MariaDB, un fork de MySQL, entre en scène.
Dans cet article, nous verrons comment installer MySQL 8.0/5.7 sur CentOS 7 / RHEL 7.
Ajouter un référentiel MySQL
MySQL n'est plus distribué via les référentiels du système d'exploitation. Vous devrez donc ajouter un référentiel officiel de MySQL pour installer le serveur de la communauté MySQL.
rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-4.noarch.rpm
Assurez-vous que le référentiel MySQL a été ajouté et activé à l'aide de la commande suivante.
yum repolist all | grep mysql | grep enabled
Sortie :peut ressembler à.
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 221 mysql-tools-community/x86_64 MySQL Tools Community enabled: 135 mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 301
Installer le serveur de communauté MySQL
Oracle propose actuellement les deux versions stables (v8.0 et v5.7). Vous pouvez choisir celui que vous souhaitez installer sur votre machine.
Installer MySQL 8.0
Utilisez la commande yum pour installer le serveur de communauté MySQL 8.0.
yum install -y mysql-community-server
Installer MySQL 5.7
Si vous souhaitez essayer l'ancienne version de MySQL, installez MySQL 5.7 sur votre machine avec la commande ci-dessous.
yum install -y mysql-community-server --disablerepo=mysql80-community --enablerepo=mysql57-community
Après l'installation de MySQL, vous pouvez démarrer le serveur MySQL en utilisant la commande suivante.
systemctl start mysqld
Ensuite, activez le service MySQL pour qu'il démarre automatiquement au démarrage du système.
systemctl enable mysqld
Enfin, vérifiez si le serveur MySQL est démarré à l'aide de la commande suivante.
systemctl status mysqld
Mot de passe racine MySQL initial
Dans CentOS/RHEL, vous pouvez trouver le mot de passe root initial de MySQL 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-11-27T08:27:27.063799Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: PJyCjhTjP1:n
Serveur MySQL sécurisé
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 initital MySQL root password The existing password for the user account root has expired. Please set a new password. New password: << Enter new MySQL root password Re-enter new password: << Re-enter new MySQL 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 as we have already set new 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 << Type Y to remove anonymous users 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 << Type Y to 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 << Type 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 << Type Y to reload privilege tables Success. All done!
Travailler avec le serveur MySQL
Connectez-vous au serveur MySQL avec l'utilisateur root et son mot de passe.
mysql -u root -p
Sortie :
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.0.27 MySQL Community Server - GPL Copyright (c) 2000, 2021, Oracle and/or its affiliates. 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
phpMyAdmin est un outil de gestion Web open source pour gérer les bases de données MySQL et MariaDB. Suivez le lien ci-dessous pour installer et configurer phpMyAdmin en fonction de votre système d'exploitation.
LIRE :Installer phpMyAdmin sur CentOS 7 / RHEL 7
Conclusion
C'est tout. J'espère que vous avez appris à installer MySQL 8.0/5.7 sur CentOS 7 / RHEL 7.