Gestione e Utilizzo di MariaDB
MariaDB è un sistema di gestione di database relazionale open-source, derivato da MySQL, con elevate prestazioni, scalabilità e affidabilità. ServBay include MariaDB, e questo articolo descriverà in dettaglio come gestire e utilizzare MariaDB su ServBay, inclusa l'installazione, la configurazione, il backup, il ripristino e l'ottimizzazione delle prestazioni.
Installazione e Configurazione di MariaDB
ServBay include MariaDB, è sufficiente assicurarsi che sia in esecuzione e configurarlo se necessario.
Avvio e Gestione del Servizio MariaDB
È possibile gestire il servizio MariaDB tramite la piattaforma di gestione di ServBay o tramite lo strumento da riga di comando servbayctl
.
Utilizzo della Piattaforma di Gestione di ServBay
- Aprire la piattaforma di gestione di ServBay.
- Navigare a "Servizi".
- Trovare il servizio MariaDB e avviare, arrestare o riavviare il servizio.
Utilizzo dello Strumento da Riga di Comando servbayctl
# Avviare il servizio MariaDB
servbayctl start mariadb 11.3
# Arrestare il servizio MariaDB
servbayctl stop mariadb 11.3
# Riavviare il servizio MariaDB
servbayctl restart mariadb 11.3
2
3
4
5
6
7
8
Configurazione di MariaDB
Il file di configurazione predefinito di MariaDB su ServBay è già ottimizzato. Se necessario, è possibile modificare il file my.cnf
nella seguente directory:
/Applications/ServBay/etc/mariadb/11.3/my.cnf
A seconda della versione di MariaDB, il file di configurazione si trova in diverse cartelle.
Connessione a MariaDB
È possibile connettersi a MariaDB utilizzando il tool da riga di comando mysql
o strumenti grafici come phpMyAdmin e Adminer.
Connessione tramite Riga di Comando
Utilizzare la connessione TCP/IP:
bashmysql -u your_username -p -h localhost -P 3306
1Utilizzare la connessione Socket:
bashmysql -u your_username -p -S /Applications/ServBay/tmp/mysql.sock
1
Connessione con phpMyAdmin e Adminer
ServBay include default phpMyAdmin e Adminer, è possibile accedervi tramite:
- Indirizzo di accesso:
https://servbay.host
In questa pagina si trovano gli ingressi a phpMyAdmin e Adminer, utilizzare il nome utente e la password ottenuti dal pannello di gestione di ServBay per il login.
Gestione del Database
Creazione del Database e degli Utenti
Creare un database:
sqlCREATE DATABASE mydatabase;
1Creare un utente e assegnare privilegi:
sqlCREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON mydatabase.* TO 'your_username'@'localhost'; FLUSH PRIVILEGES;
1
2
3
Backup e Ripristino
Backup del Database
Consigliato salvare i file di backup in questa directory:
/Applications/ServBay/backup/mariadb
Utilizzare lo strumento mysqldump
per eseguire il backup del database:
mysqldump -u your_username -p mydatabase > /Applications/ServBay/backup/mariadb/mydatabase.sql
Ripristino del Database
Utilizzare lo strumento mysql
per ripristinare il database:
mysql -u your_username -p mydatabase < /Applications/ServBay/backup/mariadb/mydatabase.sql
Ottimizzazione delle Prestazioni
MariaDB offre diverse opzioni di ottimizzazione delle prestazioni, di seguito alcune delle più comuni.
Ottimizzazione degli Indici
Assicurarsi di creare indici sulle colonne delle query più utilizzate. Ad esempio:
CREATE INDEX idx_column_name ON your_table_name(column_name);
Ottimizzazione delle Query
Utilizzare il comando EXPLAIN
per analizzare le prestazioni delle query e ottimizzarle di conseguenza. Ad esempio:
EXPLAIN SELECT * FROM your_table_name WHERE column_name = 'value';
Ottimizzazione della Configurazione
Modificare i parametri del file di configurazione per migliorare le prestazioni. Ad esempio, regolare la dimensione del buffer:
[mysqld]
innodb_buffer_pool_size = 1G
2
Gestione della Sicurezza
Assicurarsi della sicurezza del database è fondamentale, di seguito alcuni consigli per la gestione della sicurezza.
Impostare Password Sicure
Impostare password sicure per tutti gli utenti del database:
SET PASSWORD FOR 'your_username'@'localhost' = PASSWORD('your_new_password');
Backup Periodico
Eseguire backup periodici del database per prevenire la perdita di dati.
Limitare l'Accesso
Limitare l'accesso degli utenti al database, concedendo solo i privilegi necessari:
REVOKE ALL PRIVILEGES ON *.* FROM 'your_username'@'localhost';
GRANT SELECT, INSERT, UPDATE ON mydatabase.* TO 'your_username'@'localhost';
2
Problemi Comuni e Soluzioni
Impossibile Connettersi a MariaDB
Controllare se MariaDB è in esecuzione:
bashservbayctl status mariadb 11.3
1Controllare le impostazioni del firewall: Assicurarsi che il firewall permetta il passaggio della porta di MariaDB (predefinita 3306).
Problemi di Privilegi
Controllare i privilegi dell'utente:
sqlSHOW GRANTS FOR 'your_username'@'localhost';
1Concedere i privilegi necessari:
sqlGRANT ALL PRIVILEGES ON mydatabase.* TO 'your_username'@'localhost'; FLUSH PRIVILEGES;
1
2
Conclusione
MariaDB è un sistema di gestione di database potente e flessibile, integrato in ServBay per semplificare la gestione e l'utilizzo del database. Seguendo questa guida, sarà possibile installare, configurare, connettere, gestire, eseguire il backup, ripristinare e ottimizzare le prestazioni di MariaDB, garantendo un funzionamento efficiente e sicuro del database.