
MySQL è un software di sistema di gestione di database gratuito più comunemente utilizzato nelle applicazioni a tre livelli per archiviare e recuperare record e informazioni.
MySQL è stato inizialmente sviluppato da MySQL AB, ora di proprietà di Oracle Corporation. Era l'applicazione di database principale su Linux fino a quando MariaDB, un fork di MySQL, non è entrato in scena.
In questo articolo, vedremo come installare MySQL 8.0 su CentOS 8 / RHEL 8.
I passaggi menzionati in questo articolo funzioneranno solo se hai abilitato l'abbonamento su RHEL 8 o hai configurato il repository yum locale sul tuo sistema.Installa MySQL 8.0 su CentOS 8 / RHEL 8
MySQL 8.0 è disponibile per CentOS 8 / RHEL 8 sia dal repository OS AppStream che dal repository MySQL Dev Community. 1. Installa MySQL 8.0 da MySQL Dev Community 2. Installa MySQL 8.0 da AppStream1. Installa MySQL 8.0 dalla community di sviluppatori MySQL
Aggiungi il repository ufficiale di MySQL per installare il server della community MySQL.
rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
Assicurati che il repository MySQL sia stato aggiunto e abilitato utilizzando il comando seguente.
dnf repolist all | grep mysql | grep enabled
Risultato:
mysql-connectors-community MySQL Connectors Community enabled mysql-tools-community MySQL Tools Community enabled mysql80-community MySQL 8.0 Community Server enabled
Usa il comando dnf in CentOS/RHEL per installare l'ultima versione stabile di MySQL. Disabilita temporaneamente il repository AppStream per installare MySQL dalla 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
Risultato:
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. Installa MySQL 8.0 da AppStream
MySQL è ora disponibile tramite Application Stream (Red Hat Enterprise Linux 8 per x86_64 – AppStream (RPM)) per RHEL 8 e CentOS 8. Quindi, non è necessario aggiungere un repository ufficiale di MySQL per installare il server MySQL su RHEL 8.
Verifica se il repository AppStream è abilitato su RHEL 8 utilizzando il comando seguente.
subscription-manager repos --list-enabled
Risultato:
+----------------------------------------------------------+ 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
Usa il comando dnf per installare l'ultima versione di MySQL.
dnf install -y @mysql
Risultato:
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!
Gestisci il servizio del server MySQL
Dopo l'installazione di MySQL, avvia il servizio del server MySQL utilizzando il comando seguente.
systemctl start mysqld
Abilita il server MySQL all'avvio del sistema.
systemctl enable mysqld
Verifica che il server MySQL sia avviato utilizzando il comando seguente.
systemctl status mysqld
Risultato:
● 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.
Server MySQL sicuro
Installato MySQL dalla community di sviluppatori MySQL
In CentOS 8 / RHEL 8, la password di root MySQL iniziale si trova in /var/log/mysqld.log. Puoi utilizzare il comando seguente per prendere la password dal file di registro.
cat /var/log/mysqld.log | grep -i 'temporary password'
Risultato:
2021-07-02T04:08:05.488758Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: PlrS,Tw&d9q2
Ora è necessario eseguire mysql_secure_installation per proteggere l'installazione di MySQL. Questo comando si occupa di impostare la password di root, rimuovere utenti anonimi, impedire il login root da remoto, ecc.
mysql_secure_installation
Risultato:
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!
Installato MySQL da AppStream
In CentOS 8 / RHEL 8, nessuna password è impostata per l'utente root MySQL . Quindi, eseguiremo mysql_secure_installation per proteggere la tua installazione di MySQL impostando la password di root, rimuovendo utenti anonimi, non consentire l'accesso root in remoto, ecc.
mysql_secure_installation
Risultato:
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!
Lavora con MySQL Server
Accedi al server MySQL come utente root MySQL.
mysql -u root -p
Risultato:
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>
Installa phpMyAdmin
Se sei un principiante di MySQL e hai meno conoscenza della riga di comando di MySQL, prendi in considerazione l'installazione di phpMyAdmin, uno strumento di gestione basato sul Web open source per gestire i database MySQL e MariaDB.
LEGGI: Come installare phpMyAdmin con Apache su CentOS 8 / RHEL 8
LEGGI: Come installare phpMyAdmin con Nginx su CentOS 8 / RHEL 8
Note per MySQL 8.0 installato dal repository MySQL Dev Community:
MySQL 8.0 utilizza un meccanismo caching_sha2_password per l'autenticazione che impedisce alle applicazioni legacy di accedere ai database incluso phpMyAdmin in questo momento. In parole povere, non accederai a phpMyAdmin a meno che non disabilitiamo questo nuovo meccanismo di password.
Puoi disabilitare globalmente il nuovo meccanismo della password inserendo default-authentication-plugin=mysql_native_password in /etc/my.cnf (gli utenti creati dopo questa modifica avranno il meccanismo di autenticazione mysql_native_password) oppure puoi ripristinare la vecchia autenticazione nativa (mysql_native_password) per i singoli utenti (es:root) eseguendo ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '
Conclusione
In questo articolo, hai imparato come installare MySQL 8.0 su CentOS 8 / RHEL 8. Condividi il tuo feedback nella sezione commenti.