Database Management · 6 min read · Sep 26, 2025

Come installare e utilizzare MySQL 8 su Ubuntu 22.04

MySQL è una piattaforma di gestione di database relazionali gratuita e open-source alimentata da Oracle Cloud. È molto popolare grazie alla sua comprovata affidabilità, elaborazione rapida, facilità e flessibilità. Utilizza il linguaggio SQL per aggiungere, accedere e gestire il contenuto di un database. MySQL 8.0 memorizza i suoi meta-dati in un motore di archiviazione transazionale collaudato chiamato InnoDB. Funziona su architettura client/server e può essere installato su tutti i principali sistemi operativi, inclusi Ubuntu, Windows, CentOS e Debian.

Questo tutorial ti mostrerà come installare MySQL 8 su un server Ubuntu 22.04.

Prerequisiti

  • Un server che esegue Ubuntu 22.04.
  • Una password di root è configurata sul tuo server.

Iniziare

Per prima cosa, aggiorna e aggiorna tutti i pacchetti di sistema all’ultima versione eseguendo il seguente comando:

apt update -y  
apt upgrade -y

Una volta aggiornati tutti i pacchetti, puoi procedere al passaggio successivo.

Installa MySQL 8 su Ubuntu 22.04

Per impostazione predefinita, l’ultima versione del server MySQL è inclusa nel repository predefinito di Ubuntu. Puoi installarlo eseguendo il seguente comando:

apt install mysql-server -y

Una volta installato il server MySQL, puoi verificare la versione di MySQL utilizzando il seguente comando:

mysql --version

Dovresti vedere la versione di MySQL nel seguente output:

mysql  Ver 8.0.30-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))

Una volta aggiornati tutti i pacchetti, puoi procedere al passaggio successivo.

Gestisci il servizio MySQL

Per impostazione predefinita, il servizio MySQL è gestito da systemd. Puoi facilmente avviare, fermare e verificare lo stato di MySQL utilizzando il comando systemctl.

Per avviare il servizio MySQL, esegui il seguente comando:

systemctl start mysql

Per fermare il servizio MySQL, esegui il seguente comando:

systemctl stop mysql

Puoi verificare lo stato del servizio MySQL utilizzando il seguente comando:

systemctl status mysql

Dovresti vedere il seguente output:

? mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-08-21 12:47:24 UTC; 28s ago
    Process: 26157 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
   Main PID: 26185 (mysqld)
     Status: "Server is operational"
      Tasks: 41 (limit: 2242)
     Memory: 359.8M
        CPU: 1.383s
     CGroup: /system.slice/mysql.service
             ??26185 /usr/sbin/mysqld

Aug 21 12:47:23 ubuntu2204 systemd[1]: Starting MySQL Community Server...
Aug 21 12:47:24 ubuntu2204 systemd[1]: Started MySQL Community Server.

Per impostazione predefinita, MySQL ascolta sulla porta 3306. Puoi controllarlo con il seguente comando:

ss -antpl | grep -i mysql

Dovresti vedere la porta di ascolto di MySQL nel seguente output:

LISTEN 0      70         127.0.0.1:33060      0.0.0.0:*    users:(("mysqld",pid=26185,fd=21))                       
LISTEN 0      151        127.0.0.1:3306       0.0.0.0:*    users:(("mysqld",pid=26185,fd=23))                       

Una volta aggiornati tutti i pacchetti, puoi procedere al passaggio successivo.

Sicurezza dell’installazione di MySQL

Successivamente, è sempre una buona idea eseguire lo script mysql_secure_installation per abilitare alcune funzionalità di sicurezza extra, tra cui impostare una nuova password di root per MySQL, rimuovere l’utente anonimo e disabilitare il login remoto.

mysql_secure_installation

Rispondi a tutte le domande come mostrato di seguito:

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

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: 0
Please set the password for root here.

Ti verrà chiesto di impostare una nuova password come mostrato di seguito:

New password: 

Re-enter new 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.

Digita Y e premi il tasto Invio per rimuovere l’utente anonimo.

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.

Digita Y e premi il tasto Invio per disabilitare il login remoto di root.

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

Digita Y e premi il tasto Invio per rimuovere il database di test.

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

Una volta terminato, puoi procedere al passaggio successivo.

Imposta la password di root di MySQL

Per impostazione predefinita, la password di root di MySQL non è impostata. Per impostarla, connettiti alla shell di MySQL:

mysql

Una volta connesso alla shell di MySQL, imposta la password di MySQL con il seguente comando:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'securepassword';

Successivamente, esegui il seguente comando per salvare le modifiche:

mysql> FLUSH PRIVILEGES;

Successivamente, esci dalla shell di MySQL utilizzando il seguente comando:

mysql> EXIT;

Successivamente, accedi di nuovo alla shell di MySQL per verificare la password di root:

mysql -u root -p

Una volta effettuato l’accesso, entrerai nella shell di MySQL come mostrato di seguito:

Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.30-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle è un marchio registrato di Oracle Corporation e/o delle sue
affiliate. Altri nomi possono essere marchi dei rispettivi
proprietari.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

Una volta terminato, puoi procedere al passaggio successivo.

Crea un database e un utente in MySQL

Creiamo un database chiamato db1 utilizzando il seguente comando:

mysql> CREATE DATABASE db1;

Puoi verificare il tuo database creato utilizzando il seguente comando:

mysql> SHOW databases;

Otterrai il seguente output:

+--------------------+
| Database           |
+--------------------+
| db1                |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

Per cambiare il database in db1, esegui il seguente comando:

mysql> USE db1;

Per creare un utente chiamato dbuser, esegui il seguente comando:

mysql> CREATE USER 'dbuser'@'%' IDENTIFIED BY 'password';

Per concedere tutti i privilegi a dbuser su tutti i database, esegui il seguente comando:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'dbuser'@'%' WITH GRANT OPTION;

Per salvare le modifiche, esegui il seguente comando:

mysql> FLUSH PRIVILEGES;

Puoi uscire dalla shell di MySQL utilizzando il seguente comando:

mysql> EXIT;

Una volta terminato, puoi procedere al passaggio successivo.

Disinstallare il server MySQL

Se desideri rimuovere il server MySQL dal tuo server, esegui il seguente comando:

apt remove mysql-server --purge

Successivamente, rimuovi tutti i pacchetti indesiderati utilizzando il seguente comando:

apt autoremove

Conclusione

In questo post, hai imparato come installare MySQL 8 su Ubuntu 22.04. Hai anche imparato come gestire il servizio MySQL e creare un database e un utente. Ora puoi iniziare a creare nuovi database e utenti di database in MySQL.

Share: X/Twitter LinkedIn

Ricevi i nuovi post nella tua casella di posta.

Nessuno spam. Disiscriviti in qualsiasi momento.