MariaDB
 sql >> Database >  >> RDS >> MariaDB

Installazione di MariaDB 10.1 in Debian Jessie ed esecuzione di varie query MariaDB

Nel nostro ultimo articolo La storia dietro l'acquisizione di "MySQL" e l'ascesa di "MariaDB" è stata molto apprezzata. In questo articolo, abbiamo già discusso la necessità di eseguire il fork di MySQL, l'ascesa di MariaDB, le sue caratteristiche, uno studio comparativo di MariaDB e MySQL, il movimento di alcune delle aziende e delle aziende rinomate al mondo (Google, Wikipedia) da MySQL a MariaDB e molti altri aspetti tecnici e non.

Qui andremo a installare MariaDB 10.1 su Debian Jessie (Testing) e lo testerà creando piccole tabelle ed eseguendo diverse query nel processo di apprendimento e comprensione.

Installa MariaDB 10.1 su Debian Jessie

Nei sistemi Debian, si consiglia vivamente di installare "python-software-properties ', prima di procedere all'installazione di MariaDB dai repository ufficiali.

# apt-get install python-software-properties

Quindi, importa e registra la chiave GPG, che abilita apt per verificare l'integrità del software scaricato.

# apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db

Ora aggiungi il seguente repository ufficiale MariaDB al tuo file sources.list, usando il seguente comando.

# add-apt-repository 'deb http://mariadb.biz.net.id//repo/10.1/debian sid main'

Se l'aggiunta del repository genera un errore come "add-apt-repository:comando non trovato ”, è necessario installare 'software-properties-common' come mostrato di seguito.

# apt-get install software-properties-common

Aggiorna l'elenco dei Pacchetti disponibili sul sistema.

# apt-get update

Infine, installa MariaDB Server and Client, utilizzando i seguenti comandi.

# apt-get install mariadb-server mariadb-client

Se l'installazione va a buon fine, controlla la versione di MariaDB installata.

# mysql -V 

mysql  Ver 15.1 Distrib 5.5.38-MariaDB, for debian-linux-gnu (x86_64) using readline 5.1

Accedi a MariaDB usando root (non consigliato), seguito da password.

$ mysql -u root -p
Risultato campione
Welcome to the MariaDB monitor.  Commands end with ; or \g. 
Your MariaDB connection id is 28 
Server version: 5.5.38-MariaDB-1 (Debian) 

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others. 

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

MariaDB [(none)]>

NOTA :Il 'nessuno' sopra, significa che nessun database è selezionato al momento.

Esecuzione di varie query MariaDB

Come creare un utente in MariaDB. Usa la seguente sintassi per creare un utente in MariaDB.

CREATE USER 'USER_NAME' IDENTIFIED BY 'PASSWORD';

Ad esempio, per creare l'utente "sam ‘ con password ‘sam123 ', dobbiamo eseguire.

MariaDB [(none)]> CREATE USER 'sam' IDENTIFIED BY 'sam123'; 
Query OK, 0 rows affected (0.00 sec)

Ora esci MariaDB e accedi utilizzando l'utente sam .

$ mysql -u 'sam' -p 
Enter password: 

Welcome to the MariaDB monitor.  Commands end with ; or \g. 
Your MariaDB connection id is 36 
Server version: 5.5.38-MariaDB-1 (Debian) 

Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others. 

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

MariaDB [(none)]>

Elimina/rilascia l'utente MySQL 'sam'.

MariaDB [(none)]> DROP USER sam; 
Query OK, 0 rows affected (0.00 sec)

Visualizza tutti i Database disponibili.

MariaDB [(none)]> SHOW DATABASES; 

+--------------------+ 
| Database           | 
+--------------------+ 
| information_schema | 
| mysql              | 
| performance_schema | 
+--------------------+ 
3 rows in set (0.04 sec)

NOTA :Tutti i database mostrati sopra sono usati internamente da MariaDB. Non modificare questi database a meno che tu non sappia cosa stai facendo.

Seleziona un database dall'elenco (necessario per eseguire le query).

MariaDB [(none)]> USE mysql; 
Reading table information for completion of table and column names 
You can turn off this feature to get a quicker startup with -A 

Database changed 
MariaDB [mysql]>

Mostra tutte le tabelle all'interno del database.

MariaDB [mysql]> SHOW TABLES; 

| Tables_in_mysql           | 
+---------------------------+ 
| columns_priv              | 
| db                        | 
| event                     | 
| func                      | 
| general_log               | 
| help_category             | 
| help_keyword              | 
| help_relation             | 
| help_topic                | 
.....
24 rows in set (0.00 sec)

Vedi tutte le colonne di una tabella, ad esempio "utente" dal database "mysql". Usa una delle due query.

SHOW COLUMNS FROM user;

or 

DESCRIBE user;

Il risultato di entrambe le query è lo stesso.

MariaDB [mysql]> describe user; 
+------------------------+-----------------------------------+------+-----+---------+-------+ 
| Field                  | Type                              | Null | Key | Default | Extra | 
+------------------------+-----------------------------------+------+-----+---------+-------+ 
| Host                   | char(60)                          | NO   | PRI |         |       | 
| User                   | char(16)                          | NO   | PRI |         |       | 
| Password               | char(41)                          | NO   |     |         |       | 
| Select_priv            | enum('N','Y')                     | NO   |     | N       |       | 
| Insert_priv            | enum('N','Y')                     | NO   |     | N       |       | 
| Update_priv            | enum('N','Y')                     | NO   |     | N       |       | 
| Delete_priv            | enum('N','Y')                     | NO   |     | N       |       | 
| Create_priv            | enum('N','Y')                     | NO   |     | N       |       | 
| Drop_priv              | enum('N','Y')                     | NO   |     | N       |       | 
.......
42 rows in set (0.01 sec)

Visualizza informazioni dettagliate sullo stato del server di MariaDB.

MariaDB [mysql]> SHOW STATUS; 
+------------------------------------------+----------------------+ 
| Variable_name                            | Value                | 
+------------------------------------------+----------------------+ 
| Aborted_clients                          | 0                    | 
| Aborted_connects                         | 0                    | 
| Access_denied_errors                     | 0                    | 
| Aria_pagecache_blocks_not_flushed        | 0                    | 
| Aria_pagecache_blocks_unused             | 15737                | 
| Aria_pagecache_blocks_used               | 2                    | 
| Aria_pagecache_read_requests             | 176                  | 
| Aria_pagecache_reads                     | 4                    | 
| Aria_pagecache_write_requests            | 8                    | 
....
419 rows in set (0.00 sec)

Vedi l'istruzione MariaDB che è stata utilizzata per creare il database, ad esempio "mysql".

MariaDB [mysql]> SHOW CREATE DATABASE mysql; 
+----------+------------------------------------------------------------------+ 
| Database | Create Database                                                  | 
+----------+------------------------------------------------------------------+ 
| mysql    | CREATE DATABASE `mysql` /*!40100 DEFAULT CHARACTER SET latin1 */ | 
+----------+------------------------------------------------------------------+ 
1 row in set (0.00 sec)

Vedi l'istruzione MariaDB che è stata utilizzata per creare la tabella, ad esempio "utente".

MariaDB [mysql]> SHOW CREATE TABLE user; 
+ 
| Table | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
+-------
| user  | CREATE TABLE `user` ( 
  `Host` char(60) COLLATE utf8_bin NOT NULL DEFAULT '', 
  `User` char(16) COLLATE utf8_bin NOT NULL DEFAULT '', 
  `Password` char(41) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '', 
  `Select_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N', 
  `Insert_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N', 
....

Vedi i diritti di sicurezza concessi a tutti gli utenti MariaDB.

MariaDB [mysql]> SHOW GRANTS; 
+----------------------------------------------------------------------------------------------------------------------------------------+ 
| Grants for [email protected]                                                                                                              | 
+----------------------------------------------------------------------------------------------------------------------------------------+ 
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*698vsgfkemhvjh7txyD863DFF63A6bdfj8349659232234bs3bk5DC1412A' WITH GRANT OPTION | 
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION                                                                           | 
+----------------------------------------------------------------------------------------------------------------------------------------+ 
2 rows in set (0.00 sec)

Vedi le AVVERTENZE del server MariaDB.

MariaDB [mysql]> SHOW WARNINGS; 
+--------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| Level | Code |Message                                                                                                                                                      | 
+-------+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| Error | 1064 | You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ON mysql' at line 1 | 
+-------+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
1 row in set (0.00 sec)

Vedi Errori del servizio MariaDB.

MariaDB [mysql]> SHOW ERRORS; 

+-------+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| Level | Code | Message                                                                                                                                                      | 
+-------+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| Error | 1064 | You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ON mysql' at line 1 | 
+-------+------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
1 row in set (0.00 sec)

È tutto per ora. Il "MOSTRA La dichiarazione ha molte funzionalità, di cui parleremo in futuro articolo insieme ad altre query da eseguire su MariaDB per ottenere il risultato desiderato. Fino ad allora restate sintonizzati e collegati a Tecmint. Non dimenticare di fornirci il tuo prezioso feedback nella sezione commenti qui sotto.