GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Come installare e configurare Mariadb 10 in Ubuntu 20.04

MariaDB è stato sviluppato come fork software di MySQL nel 2009 in risposta all'acquisizione di MySQL da parte di Oracle. MariaDB intende rimanere un software libero e open source sotto la GNU General Public License. Fa parte della maggior parte delle offerte cloud ed è l'impostazione predefinita nella maggior parte delle distribuzioni Linux.

In questa guida impareremo come installare e configurare MariaDB in Debian 11.

Post correlati

  • Come installare Mysql 8 su Rocky Linux/Centos 8
  • Come installare e configurare mysql 8 su Ubuntu 20.04
  • Come installare e configurare Mariadb 10 in Debian 11

Prerequisiti

Per seguire, assicurati di avere:

  • Un server Ubuntu 20.04 aggiornato
  • Accesso root al server o utente con accesso Sudo
  • Accesso a Internet dal server

Indice dei contenuti

  1. Aggiorna sistema
  2. Installazione di Mariadb
  3. Configurazione di Mariadb
  4. Facoltativo:regolazione dell'autenticazione utente e dei privilegi
  5. Testare MariaDB

1. Aggiorna il sistema

Prima di procedere assicuriamoci che il server Ubuntu sia aggiornato. Prima aggiorna i repository, quindi esegui un aggiornamento del sistema per assicurarti che tutti i pacchetti installati siano aggiornati:

Nel tuo terminale, digita questi. Il -y opzione in apt upgrade è garantire che il sistema non si interrompa per accettare l'aggiornamento.

$ sudo apt update
$ sudo apt upgrade -y

2. Installazione di mariadb

Mariadb si trova nei repository predefiniti per debian. Utilizzare questo comando per installare il server del database:

sudo apt install -y mariadb-server

Mariadb verrà avviato per impostazione predefinita.

$ sudo systemctl status mariadb
● mariadb.service - MariaDB 10.3.31 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-11-14 16:48:17 EAT; 43s ago
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 50510 (mysqld)
     Status: "Taking your SQL requests now..."
      Tasks: 31 (limit: 4631)
     Memory: 63.8M
     CGroup: /system.slice/mariadb.service
             └─50510 /usr/sbin/mysqld

Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: Processing databases
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: information_schema
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: mysql
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: performance_schema
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: Phase 6/7: Checking and upgrading tables
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: Processing databases
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: information_schema
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: performance_schema
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Nov 14 16:48:18 ubuntu-client.citizix.com /etc/mysql/debian-start[50549]: OK

3. Configurazione di MariaDB

Per le nuove installazioni di MariaDB, il passaggio successivo è eseguire lo script di sicurezza incluso. Questo script modifica alcune delle opzioni predefinite meno sicure. Lo useremo per bloccare il root remoto accessi e per rimuovere gli utenti del database inutilizzati.

Esegui lo script di sicurezza:

sudo mysql_secure_installation

Questo ti guiderà attraverso una serie di prompt in cui puoi apportare alcune modifiche alle opzioni di sicurezza dell'installazione di MariaDB. La prima richiesta ti chiederà di inserire il database corrente root parola d'ordine. Poiché non ne abbiamo ancora impostato uno, premi ENTER per indicare “nessuno”.

La richiesta successiva ti chiede se desideri configurare un database root parola d'ordine. Digita N e quindi premi ENTER . In Debian, il root l'account per MariaDB è strettamente legato alla manutenzione automatizzata del sistema, quindi non dovremmo modificare i metodi di autenticazione configurati per quell'account. Ciò consentirebbe a un aggiornamento del pacchetto di interrompere il sistema del database rimuovendo l'accesso all'account amministrativo. Successivamente, illustreremo come configurare facoltativamente un account amministrativo aggiuntivo per l'accesso tramite password se l'autenticazione socket non è appropriata per il tuo caso d'uso.

Da lì, puoi premere Y e poi ENTER accettare le impostazioni predefinite per tutte le domande successive. Ciò rimuoverà alcuni utenti anonimi e il database di test, disabiliterà il root remoto login e caricare queste nuove regole in modo che MariaDB rispetti immediatamente le modifiche che hai apportato.

Questo è l'output del mio server

$ sudo mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 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? [Y/n] Y
 ... Success!

By default, MariaDB 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? [Y/n] 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? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

5. Test di MariaDB

Ora che mariadb è tutto configurato ed è in esecuzione, dobbiamo confermare che può accettare connessioni.

Per eseguire il test, connettiti a mariadb con l'utente root – mysql -h 127.0.0.1 -u root -p

Uscita:

$ mysql -h 127.0.0.1 -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 54
Server version: 10.5.12-MariaDB-0+deb11u1 Debian 11

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]>

Controlla la versione di mariadb:

MariaDB [(none)]> SELECT VERSION();
+----------------------------------+
| VERSION()                        |
+----------------------------------+
| 10.3.31-MariaDB-0ubuntu0.20.04.1 |
+----------------------------------+
1 row in set (0.000 sec)

MariaDB [(none)]>

Per un ulteriore controllo, puoi provare a connetterti al database utilizzando il mysqladmin tool, che è un client che consente di eseguire comandi amministrativi. Ad esempio, questo comando dice di connettersi a MariaDB come root e restituire la versione utilizzando il socket Unix:

sudo mysqladmin version

Dovresti ricevere un output simile a questo:

$ sudo mysqladmin version
mysqladmin  Ver 9.1 Distrib 10.3.31-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Server version		10.3.31-MariaDB-0ubuntu0.20.04.1
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/var/run/mysqld/mysqld.sock
Uptime:			13 min 56 sec

Threads: 6  Questions: 488  Slow queries: 0  Opens: 175  Flush tables: 1  Open tables: 31  Queries per second avg: 0.583

Conclusione

In questa guida hai installato MariaDB per fungere da server SQL. Durante il processo di installazione hai anche protetto il server.


Ubuntu
  1. Come installare e configurare Redis su Ubuntu 18.04

  2. Come installare e configurare Redmine su Ubuntu 18.04

  3. Come installare e configurare Samba su Ubuntu 18.04

  4. Come installare e configurare Redis su Ubuntu 20.04

  5. Come installare e configurare Jenkins su Ubuntu 20.04

Come installare e configurare Neo4j su Ubuntu 20.04

Come installare e configurare Ubuntu SDK in Ubuntu 16.04 e 14.04

Come installare e configurare PostgreSQL su Ubuntu

Come installare e configurare Hadoop su Ubuntu 20.04

Come installare e configurare Jenkins su Ubuntu

Come installare e configurare Jenkins in Ubuntu 20.04