Debian 10: Installing MySQL (not MariaDB)
Sommario:
- Prerequisiti
- Passaggio 1: configurazione del repository MySQL
- Passaggio 3: verifica dell'installazione di MySQL
- Passaggio 4: protezione di MySQL
- Passaggio 5: connettersi a MySQL dalla riga di comando
- Crea un database
- Crea tabelle
- Conclusione
Con il rilascio di Debian 9 Stretch MySQL, il sistema di gestione di database relazionali open source più famoso al mondo non è più disponibile nei repository di Debian e MariaDB è diventato il sistema di database predefinito. MariaDB è una sostituzione drop-in binaria compatibile con le versioni precedenti di MySQL.
In questo tutorial, ti mostreremo come installare e proteggere MySQL su una macchina Debian 9 dal repository Apt di MySQL. Se la tua applicazione non ha requisiti specifici, dovresti seguire MariaDB, il sistema di database predefinito in Debian 9.
Prerequisiti
Prima di continuare con questo tutorial, assicurati di aver effettuato l'accesso come utente con privilegi sudo.
Passaggio 1: configurazione del repository MySQL
Per aggiungere il repository APT MySQL al tuo sistema vai alla pagina di download del repository e scarica l'ultimo pacchetto di rilascio usando il seguente comando wget:
wget
Una volta completato il download, installare il pacchetto di rilascio con il seguente comando:
sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb
Ti verrà presentato il menu di configurazione in cui è possibile selezionare la versione di MySQL che si desidera installare.
Passaggio 3: verifica dell'installazione di MySQL
Una volta completata l'installazione, il servizio MySQL si avvierà automaticamente.
Possiamo verificare lo stato del servizio MySQL digitando:
sudo systemctl status mysql
● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: Active: active (running) since Thu 2018-08-02 17:22:18 UTC; 18s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 14797 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (co Main PID: 14832 (mysqld) Status: "SERVER_OPERATING" Tasks: 37 (limit: 4915) CGroup: /system.slice/mysql.service └─14832 /usr/sbin/mysqld
Passaggio 4: protezione di MySQL
Esegui il comando
mysql_secure_installation
per impostare la password di root e migliorare la sicurezza dell'installazione di MySQL:
sudo mysql_secure_installation
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:
Ti verrà chiesto di configurare il
VALIDATE PASSWORD PLUGIN
che viene utilizzato per testare la forza delle password degli utenti MySQL. Esistono tre livelli di criteri di convalida della password, basso, medio e forte. Premere
ENTER
se non si desidera impostare il plug-in di convalida password.
Please set the password for root here. New password: Re-enter new password:
Al prompt successivo, ti verrà chiesto di impostare una password per l'utente root di MySQL.
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!
Dopo aver impostato la password di root, lo script ti chiederà anche di rimuovere l'utente anonimo, limitare l'accesso dell'utente root al computer locale e rimuovere il database di test. Devi rispondere "Y" (sì) a tutte le domande.
Passaggio 5: connettersi a MySQL dalla riga di comando
Per interagire con MySQL attraverso il terminale utilizzeremo il client MySQL installato come dipendenza del pacchetto server MySQL.
Per accedere al server MySQL come tipo di utente root:
mysql -u root -p
Ti verrà richiesto di inserire la password di root che hai impostato in precedenza quando è stato eseguito lo script
mysql_secure_installation
.
Una volta inserita la password ti verrà presentata la shell MySQL come mostrato di seguito:
Welcome to the MySQL monitor. Commands end with; or \g. Your MySQL connection id is 10 Server version: 8.0.12 MySQL Community Server - GPL 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>
Crea un database
Una volta connesso alla shell MySQL, è possibile creare un nuovo database digitando il comando seguente:
CREATE DATABASE new_database;
Query OK, 1 row affected (0.00 sec)
Crea tabelle
Ora che abbiamo creato un database, possiamo creare una tabella per memorizzare alcuni dati.
Prima di eseguire le istruzioni SQL per la creazione di una tabella, è necessario connettersi al database:
use new_database;
In questo esempio creeremo una semplice tabella denominata
contacts
con tre campi,
id
,
name
ed e
email
:
CREATE TABLE contacts (id INT PRIMARY KEY, name VARCHAR(30), email VARCHAR(30));
Query OK, 1 row affected (0.00 sec)
Conclusione
In questo tutorial, ti abbiamo mostrato come installare e proteggere un server MySQL su un server Debian 9. Ti abbiamo anche mostrato come connetterti alla shell MySQL e come creare un nuovo database e una nuova tabella.
Ora che il tuo server MySQL è attivo e in esecuzione e sai come connetterti al server MySQL dalla riga di comando, potresti voler controllare le seguenti guide:
mysql debianCome installare, installare la stampante multifunzione HP Officejet 6500a plus

Scopri come impostare e installare la stampante multifunzione HP Officejet 6500A Plus.
Come installare e utilizzare mysql workbench su Ubuntu 18.04

MySQL Workbench è un'applicazione grafica multipiattaforma per amministratori e architetti di database MySQL. In questo tutorial ti mostreremo come installare e MySQL Workbench su Ubuntu 18.04.
Come installare mysql su debian 10 linux

MySQL, il sistema di gestione di database relazionali open source più famoso al mondo non è disponibile nei repository predefiniti di Debian. Questo tutorial spiega come installare e proteggere MySQL su Debian 10 dal repository Apt di MySQL.