MariaDB 10.1 instalēšana Debian Jessie un dažādu MariaDB vaicājumu izpildīšana


Mūsu pēdējā rakstā “MySQL” iegādes stāsts un “MariaDB” pieaugums tika augstu novērtēts. Šajā rakstā mēs jau esam apsprieduši nepieciešamību diktēt MySQL, MariaDB pieaugumu, tā iezīmes, MariaDB un MySQL salīdzinošu pētījumu, dažu pasaulē pazīstamu korporāciju un uzņēmumu (Google, Wikipedia) pārvietošanos no MySQL uz MariaDB un daudz citu tā tehnisko un netehnisko aspektu.

Šeit mēs instalēsim MariaDB 10.1 uz Debian Jessie (Testing) un pārbaudīsim to, izveidojot nelielas tabulas un izpildot vairākus vaicājumus mācību un izpratnes procesā.

Instalējiet MariaDB 10.1 uz Debian Jessie

Pirms došanās uz MariaDB instalāciju no oficiālajiem krātuvēm, Debian sistēmās ir ļoti ieteicams instalēt paketi python-software-properties .

# apt-get install python-software-properties

Pēc tam importējiet un reģistrējiet GPG atslēgu, kas ļauj apt pārbaudīt tās lejupielādētās programmatūras integritāti.

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

Tagad pievienojiet šādu oficiālo MariaDB repozitoriju failam sources.list, izmantojot šādu komandu.

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

Ja pievienojot repozitoriju, tiek pieļauta kļūda, piemēram, “ add-apt-repository: komanda nav atrasta ”, jums jāinstalē ‘software-properties-common’, kā parādīts zemāk.

# apt-get install software-properties-common

Atjauniniet sistēmā pieejamo pakotņu sarakstu.

# apt-get update

Visbeidzot, instalējiet MariaDB Server un klientu, izmantojot šādas komandas.

# apt-get install mariadb-server mariadb-client

Ja instalēšana norit gludi, pārbaudiet instalētās MariaDB versiju.

# mysql -V 

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

Piesakieties MariaDB, izmantojot root (nav ieteicams), kam seko parole.

$ mysql -u root -p
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)]>

PIEZĪME. Iepriekš redzamais “neviens” nozīmē, ka pašlaik nav atlasīta datu bāze.

Dažādu MariaDB vaicājumu izpilde

Kā izveidot lietotāju MariaDB. Izmantojiet šo sintaksi, lai izveidotu lietotāju MariaDB.

CREATE USER 'USER_NAME' IDENTIFIED BY 'PASSWORD';

Piemēram, lai izveidotu lietotāju ‘ sam ’ ar paroli ‘ sam123 ’, mums tas ir jāizpilda.

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

Tagad izejiet no MariaDB un piesakieties, izmantojot lietotāju 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)]>

Dzēst/nomest MySQL lietotāju ‘sam’.

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

Skatiet visu pieejamo datu bāzi.

MariaDB [(none)]> SHOW DATABASES; 

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

PIEZĪME. Visas iepriekš redzamās datubāzes MariaDB izmanto iekšēji. Nerediģējiet šīs datu bāzes, ja vien nezināt, ko darāt.

Sarakstā atlasiet datu bāzi (nepieciešams, lai palaistu vaicājumus).

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

Parādīt visas tabulas datu bāzē.

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)

Skatīt visas tabulas slejas, sakot “lietotājs” no datu bāzes “mysql”. Izmantojiet vienu no abiem vaicājumiem.

SHOW COLUMNS FROM user;

or 

DESCRIBE user;

Abu vaicājumu rezultāts ir vienāds.

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)

Skatiet plašu MariaDB servera statusa informāciju.

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)

Skatiet MariaDB paziņojumu, kas tika izmantots, lai izveidotu datu bāzi, sakot “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)

Skatiet MariaDB paziņojumu, kas tika izmantots, lai izveidotu tabulu, sakot “lietotājs”.

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', 
....

Skatiet drošības tiesības, kas piešķirtas visiem MariaDB lietotājiem.

MariaDB [mysql]> SHOW GRANTS; 
+----------------------------------------------------------------------------------------------------------------------------------------+ 
| Grants for [email                                                                                                               | 
+----------------------------------------------------------------------------------------------------------------------------------------+ 
| 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)

Skatiet MariaDB servera BRĪDINĀJUMUS.

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)

Skatiet MariaDB servisa kļūdas.

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)

Tas pagaidām ir viss. Paziņojumā “RĀDĪT” ir daudz funkciju, kuras mēs apspriedīsim nākamajā rakstā kopā ar citiem vaicājumiem, kas jāizpilda MariaDB, lai iegūtu vēlamo rezultātu. Līdz tam sekojiet līdzi un sazinieties ar Tecmint. Neaizmirstiet sniegt mums vērtīgas atsauksmes komentāru sadaļā zemāk.