Cum se instalează MySQL 8.0 pe RHEL/CentOS 8/7 și Fedora 35


MySQL este un sistem de gestionare a bazelor de date relaționale gratuit (RDBMS) lansat sub GNU (Licență publică generală) . Este folosit pentru a rula mai multe baze de date pe un singur server, oferind acces multi-utilizator la fiecare bază de date creată.

Acest articol vă va prezenta procesul de instalare și actualizare a celei mai recente versiuni MySQL 8.0 pe RHEL/CentOS 8/7/6/ și Fedora utilizând depozitul MySQL Yum prin utilitarul YUM.

Pasul 1: Adăugarea depozitului MySQL Yum

1. Vom folosi depozitul oficial de software MySQL Yum, care va furniza pachete RPM pentru instalarea celei mai recente versiuni de server MySQL, client, Utilitare MySQL, MySQL Workbench, Connector/ ODBC și conector/Python pentru RHEL/CentOS 8/7/6/ și Fedora 30-35.

Important: aceste instrucțiuni funcționează numai la o nouă instalare a MySQL pe server, dacă există deja un MySQL > instalat folosind un pachet RPM distribuit de terțe părți, apoi vă recomand să actualizați sau să înlocuiți pachetul MySQL instalat folosind MySQL Yum Repository ”.

Înainte de a actualiza sau de a înlocui un pachet MySQL vechi, nu uitați să luați toate fișierele de backup și de configurare importante ale bazei de date folosind ghidul nostru de copiere de rezervă a bazelor de date MySQL.

2. Acum descărcați și adăugați următorul depozitiv MySQL Yum la lista de depozite a sistemului de distribuție Linux respectiv pentru a instala cea mai recentă versiune de MySQL (adică 8.0 lansat pe 27 iulie 2018).

--------------- On RHEL/CentOS 8 ---------------
wget https://repo.mysql.com/mysql80-community-release-el8-1.noarch.rpm
--------------- On RHEL/CentOS 7 ---------------
wget https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
--------------- On RHEL/CentOS 6 ---------------
wget https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm
--------------- On Fedora 35 ---------------
wget https://dev.mysql.com/get/mysql80-community-release-fc35-1.noarch.rpm
--------------- On Fedora 34 ---------------
wget https://dev.mysql.com/get/mysql80-community-release-fc34-1.noarch.rpm
--------------- On Fedora 33 ---------------
wget https://dev.mysql.com/get/mysql80-community-release-fc33-1.noarch.rpm

3. După descărcarea pachetului pentru platforma dvs. Linux, acum instalați pachetul descărcat cu următoarea comandă.

--------------- On RHEL/CentOS 8 ---------------
yum localinstall mysql80-community-release-el8-1.noarch.rpm
--------------- On RHEL/CentOS 7 ---------------
yum localinstall mysql80-community-release-el7-1.noarch.rpm
--------------- On RHEL/CentOS 6 ---------------
yum localinstall mysql80-community-release-el6-1.noarch.rpm
--------------- On Fedora 35 ---------------
dnf localinstall mysql80-community-release-fc35-1.noarch.rpm
--------------- On Fedora 34 ---------------
dnf localinstall mysql80-community-release-fc34-1.noarch.rpm
--------------- On Fedora 33 ---------------
yum localinstall mysql80-community-release-fc33-1.noarch.rpm

Comanda de instalare de mai sus adaugă depozitul MySQL Yum la lista de depozite a sistemului și descarcă cheia GnuPG pentru a verifica integritatea pachetelor.

4. Puteți verifica dacă depozitul MySQL Yum a fost adăugat cu succes utilizând următoarea comandă.

yum repolist enabled | grep "mysql.*-community.*"
dnf repolist enabled | grep "mysql.*-community.*"      [On Fedora versions]

Pasul 2: Instalarea celei mai recente versiuni MySQL

5. Instalați cea mai recentă versiune de MySQL (în prezent 8.0) utilizând următoarea comandă.

yum install mysql-community-server
dnf install mysql-community-server      [On Fedora versions]

Comanda de mai sus instalează toate pachetele necesare pentru serverul MySQL mysql-community-server, mysql-community-client, mysql-community-common și mysql-community-libs.

Pasul 3: Instalarea diferitelor versiuni de lansare MySQL

6. De asemenea, puteți instala diferite versiuni MySQL folosind diferite sub-repozitive ale MySQL Community Server. Sub-repozitivul pentru seria MySQL recentă (în prezent MySQL 8.0) este activat implicit, iar sub-depozitele pentru toate celelalte versiuni (de exemplu, seria MySQL 5.x) sunt dezactivate implicit .

Pentru a instala o anumită versiune dintr-un anumit sub-depozitiv, puteți utiliza opțiunile --enable sau --disable folosind yum-config-manager sau dnf config-manager după cum se arată:

yum-config-manager --disable mysql57-community
yum-config-manager --enable mysql56-community
------------------ Fedora Versions ------------------
dnf config-manager --disable mysql57-community
dnf config-manager --enable mysql56-community

Pasul 4: Pornirea serverului MySQL

7. După instalarea cu succes a MySQL, este timpul să porniți și să activați serverul MySQL cu următoarele comenzi:

service mysqld start
systemctl enable mysqld.service

Puteți verifica starea serverului MySQL cu ajutorul următoarei comenzi.

systemctl status mysqld.service
OR
service mysqld status

Acesta este exemplul de ieșire al rulării MySQL sub caseta mea CentOS 7.

Redirecting to /bin/systemctl status  mysqld.service
mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
   Active: active (running) since Thu 2015-10-29 05:15:19 EDT; 4min 5s ago
  Process: 5314 ExecStart=/usr/sbin/mysqld --daemonize $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 5298 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 5317 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─5317 /usr/sbin/mysqld --daemonize

Oct 29 05:15:19 localhost.localdomain systemd[1]: Started MySQL Server.

8. Acum verificați în sfârșit versiunea MySQL instalată folosind următoarea comandă.

mysql --version

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

Pasul 5: Securizarea instalării MySQL

9. Comanda mysql_secure_installation vă permite să vă securizați instalarea MySQL prin efectuarea de setări importante, cum ar fi setarea parolei root, eliminarea utilizatorilor anonimi, eliminarea autentificarii root și așa mai departe.

Notă: versiunea MySQL 8.0 sau o versiune superioară generează o parolă aleatorie temporară în /var/log/mysqld.log după instalare.

Utilizați comanda de mai jos pentru a vedea parola înainte de a rula comanda securizată MySQL.

grep 'temporary password' /var/log/mysqld.log

Odată ce știți parola, puteți rula următoarea comandă pentru a vă asigura instalarea MySQL.

mysql_secure_installation

Notă: Introduceți o nouă parolă Root înseamnă parola dvs. temporară dintr-un fișier /var/log/mysqld.log.

Acum urmați cu atenție instrucțiunile de pe ecran, pentru referință vedeți rezultatul comenzii de mai sus de mai jos.

Ieșire eșantion
Securing the MySQL server deployment.

Enter password for user root: Enter New Root Password

VALIDATE PASSWORD PLUGIN 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 plugin?

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: 2
Using existing password for root.

Estimated strength of the password: 50 
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: Set New MySQL Password

Re-enter new password: Re-enter New MySQL 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! 

Pasul 6: Conectarea la serverul MySQL

10. Conectați-vă la un server MySQL nou instalat furnizând un nume de utilizator și o parolă.

mysql -u root -p

Eșantion de ieșire:

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>

Pasul 7: Actualizarea MySQL cu Yum

11. Pe lângă instalarea proaspătă, puteți face și actualizări pentru produsele și componentele MySQL cu ajutorul următoarei comenzi.

yum update mysql-server
dnf update mysql-server       [On Fedora versions]

Când sunt disponibile actualizări noi pentru MySQL, acesta le va instala automat, dacă nu, veți primi un mesaj care spune NU există pachete marcate pentru actualizări.

Gata, ați instalat cu succes MySQL 8.0 pe sistemul dvs. Dacă întâmpinați probleme la instalare, nu ezitați să folosiți secțiunea noastră de comentarii pentru soluții.