MySQL è un sistema di gestione di database gratuito e open source, comunemente utilizzato nelle applicazioni Web 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 per il sistema operativo Linux fino a quando MariaDB, un fork di MySQL, non è entrato in scena.
In questo articolo vedremo come installare MySQL 8.0/5.7 su CentOS 7 / RHEL 7.
Aggiungi repository MySQL
MySQL non è più distribuito tramite i repository del sistema operativo. Quindi, dovresti aggiungere un repository ufficiale di MySQL per installare il server della community MySQL.
rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-4.noarch.rpm
Assicurati che il repository MySQL sia stato aggiunto e abilitato utilizzando il comando seguente.
yum repolist all | grep mysql | grep enabled
Output:potrebbe sembrare.
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
Installa MySQL Community Server
Oracle attualmente offre entrambe le versioni stabili (v8.0 e v5.7). Puoi scegliere quello che desideri installare sulla tua macchina.
Installa MySQL 8.0
Usa il comando yum per installare MySQL Community Server 8.0.
yum install -y mysql-community-server
Installa MySQL 5.7
Se vuoi provare la versione precedente di MySQL, installa MySQL 5.7 sul tuo computer con il comando seguente.
yum install -y mysql-community-server --disablerepo=mysql80-community --enablerepo=mysql57-community
Dopo l'installazione di MySQL, puoi avviare il server MySQL usando il comando seguente.
systemctl start mysqld
Quindi, abilita il servizio MySQL per l'avvio automatico all'avvio del sistema.
systemctl enable mysqld
Infine, verifica se il server MySQL è stato avviato utilizzando il comando seguente.
systemctl status mysqld
Password radice MySQL iniziale
In CentOS/RHEL, puoi trovare la password di root MySQL iniziale 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-11-27T08:27:27.063799Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: PJyCjhTjP1:n
Server MySQL sicuro
Ora devi 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 di root da remoto, ecc.
mysql_secure_installation
Risultato:
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!
Lavora con MySQL Server
Accedi al server MySQL con l'utente root e la relativa password.
mysql -u root -p
Risultato:
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>
Installa phpMyAdmin
phpMyAdmin è uno strumento di gestione basato sul Web open source per gestire i database MySQL e MariaDB. Segui il link sottostante per installare e configurare phpMyAdmin in base al tuo sistema operativo.
LEGGI:Installa phpMyAdmin su CentOS 7 / RHEL 7
Conclusione
È tutto. Spero che tu abbia imparato a installare MySQL 8.0/5.7 su CentOS 7 / RHEL 7.