author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Sat, 10 Feb 2018 01:28:53 +0200 | |
changeset 2227 | 1e9323e7ec88 |
parent 1912 | 8b81a8f0f692 |
child 2228 | 837f1337c59b |
permissions | -rw-r--r-- |
1809 | 1 |
.. -*- coding: utf-8; -*- |
2 |
||
3 |
================ |
|
4 |
MySQL/MariaBD. |
|
5 |
================ |
|
6 |
.. contents:: |
|
1905
fba288d59662
Include only local subsections into TOC. This prevent duplication of
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1880
diff
changeset
|
7 |
:local: |
1809 | 8 |
|
9 |
SQL clients. |
|
10 |
============ |
|
11 |
||
1810 | 12 |
https://mariadb.com/kb/en/mariadb/clients-and-utilities/ |
13 |
Clients and Utilities. |
|
14 |
https://mariadb.com/kb/en/mariadb/graphical-and-enhanced-clients/ |
|
15 |
Graphical and Enhanced Clients. |
|
16 |
||
1809 | 17 |
mysql. |
18 |
------ |
|
19 |
||
20 |
Official client. Install ``mariadb-client`` package - ``mysql`` utility |
|
21 |
will be installed with dependent package. |
|
22 |
||
23 |
Usage:: |
|
24 |
||
25 |
$ mysql -u $USER -p |
|
26 |
Enter password: <== Type password. |
|
27 |
||
1851
e6ffc5f7200e
To save content of session interaction.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1850
diff
changeset
|
28 |
To save content of session interaction in ``mysql`` use:: |
e6ffc5f7200e
To save content of session interaction.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1850
diff
changeset
|
29 |
|
e6ffc5f7200e
To save content of session interaction.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1850
diff
changeset
|
30 |
mysql> tee out.txt |
e6ffc5f7200e
To save content of session interaction.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1850
diff
changeset
|
31 |
|
1809 | 32 |
mycli. |
33 |
------ |
|
34 |
||
35 |
Python command line client with completion. Usage:: |
|
36 |
||
37 |
$ mycli -u $USER |
|
38 |
Password: <== Type password. |
|
39 |
||
1880 | 40 |
List databases, tables, columns, indexes. |
41 |
========================================= |
|
1811
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
42 |
:: |
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
43 |
|
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
44 |
$ mysql -u $USER -p |
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
45 |
Enter password: <== Type password. |
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
46 |
|
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
47 |
SHOW DATABASES; |
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
48 |
|
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
49 |
USE mysql; |
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
50 |
MariaDB [mysql]> SHOW TABLES; |
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
51 |
|
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
52 |
MariaDB [mysql]> SHOW COLUMNS FROM user; |
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
53 |
|
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
54 |
MariaDB [mysql]> DESCRIBE user; |
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
55 |
|
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
56 |
MariaDB [mysql]> SHOW STATUS; |
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
57 |
|
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
58 |
MariaDB [mysql]> SHOW CREATE DATABASE mysql; |
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
59 |
MariaDB [mysql]> SHOW CREATE TABLE user; |
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
60 |
|
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
61 |
MariaDB [mysql]> SHOW GRANTS; |
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
62 |
|
1880 | 63 |
List indexes:: |
64 |
||
65 |
SELECT * FROM INFORMATION_SCHEMA.STATISTICS; |
|
66 |
||
67 |
SHOW INDEX FROM tbl; |
|
68 |
||
69 |
SHOW INDEX FROM tbl FROM db; |
|
70 |
||
71 |
SHOW CREATE TABLE tbl; |
|
72 |
||
1877 | 73 |
Table/index sizes. |
74 |
================== |
|
75 |
:: |
|
1876 | 76 |
|
77 |
MariaDB [mysql]> SHOW TABLE STATUS FROM mydb; |
|
78 |
||
1878 | 79 |
:: |
80 |
||
1877 | 81 |
SELECT |
1878 | 82 |
table_schema "Database", |
83 |
ROUND(SUM(data_length+index_length)/1024/1024, 2) "Size, MiB" |
|
84 |
FROM information_schema.TABLES |
|
85 |
GROUP BY table_schema; |
|
86 |
||
87 |
SELECT |
|
1879 | 88 |
table_schema AS `Database`, |
89 |
table_name, |
|
90 |
table_rows, |
|
1878 | 91 |
round(((data_length + index_length) / 1024 / 1024), 2) `Size, MiB` |
1877 | 92 |
FROM information_schema.TABLES |
93 |
ORDER BY (data_length + index_length) DESC; |
|
94 |
||
95 |
SELECT |
|
1878 | 96 |
table_schema as `Database`, |
97 |
table_name AS `Table`, |
|
98 |
round((data_length / 1024 / 1024), 2) `Data, MiB`, |
|
99 |
round((index_length / 1024 / 1024), 2) `Index, MiB`, |
|
100 |
round(((data_length+index_length) / 1024 / 1024), 2) `Total, MiB` |
|
1877 | 101 |
FROM information_schema.TABLES |
102 |
ORDER BY (data_length + index_length) DESC; |
|
103 |
||
1849
a3b639d803e7
System information.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1836
diff
changeset
|
104 |
System information. |
a3b639d803e7
System information.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1836
diff
changeset
|
105 |
=================== |
a3b639d803e7
System information.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1836
diff
changeset
|
106 |
|
a3b639d803e7
System information.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1836
diff
changeset
|
107 |
Server version, platform, etc:: |
a3b639d803e7
System information.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1836
diff
changeset
|
108 |
|
a3b639d803e7
System information.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1836
diff
changeset
|
109 |
[mysql]> SHOW VARIABLES LIKE "%version%"; |
a3b639d803e7
System information.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1836
diff
changeset
|
110 |
|
1850
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
111 |
Debugging queries error. |
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
112 |
======================== |
1836 | 113 |
|
114 |
After error or warning run:: |
|
115 |
||
1811
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
116 |
MariaDB [mysql]> SHOW WARNINGS; |
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
117 |
MariaDB [mysql]> SHOW ERRORS; |
1836 | 118 |
MariaDB [mysql]> show engine innodb status; |
1811
072cc8a704ce
List databases, tables, columns.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1810
diff
changeset
|
119 |
|
1854
9b224b68c1e1
Debugging quiery performance.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1853
diff
changeset
|
120 |
Debugging quiery performance. |
9b224b68c1e1
Debugging quiery performance.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1853
diff
changeset
|
121 |
============================= |
9b224b68c1e1
Debugging quiery performance.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1853
diff
changeset
|
122 |
:: |
9b224b68c1e1
Debugging quiery performance.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1853
diff
changeset
|
123 |
|
9b224b68c1e1
Debugging quiery performance.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1853
diff
changeset
|
124 |
explain select 1; |
9b224b68c1e1
Debugging quiery performance.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1853
diff
changeset
|
125 |
|
9b224b68c1e1
Debugging quiery performance.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1853
diff
changeset
|
126 |
.. |
9b224b68c1e1
Debugging quiery performance.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1853
diff
changeset
|
127 |
|
9b224b68c1e1
Debugging quiery performance.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1853
diff
changeset
|
128 |
https://mariadb.com/kb/en/mariadb/explain/ |
9b224b68c1e1
Debugging quiery performance.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1853
diff
changeset
|
129 |
Syntax and transcription of EXPLAIN. |
9b224b68c1e1
Debugging quiery performance.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1853
diff
changeset
|
130 |
|
1850
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
131 |
Monitor server execution. |
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
132 |
========================= |
1852
f572f646694b
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1851
diff
changeset
|
133 |
|
f572f646694b
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1851
diff
changeset
|
134 |
List all current executions:: |
1850
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
135 |
|
1852
f572f646694b
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1851
diff
changeset
|
136 |
MariaDB [mysql]> show processlist; |
f572f646694b
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1851
diff
changeset
|
137 |
|
1875
340162fb09a2
Stop selected process
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1854
diff
changeset
|
138 |
Stop selected process:: |
340162fb09a2
Stop selected process
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1854
diff
changeset
|
139 |
|
340162fb09a2
Stop selected process
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1854
diff
changeset
|
140 |
MariaDB [mysql]> kill 12; |
340162fb09a2
Stop selected process
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1854
diff
changeset
|
141 |
|
1852
f572f646694b
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1851
diff
changeset
|
142 |
Dump execution plan for selected process:: |
f572f646694b
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1851
diff
changeset
|
143 |
|
f572f646694b
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1851
diff
changeset
|
144 |
MariaDB [mysql]> show explain for 1; |
1850
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
145 |
|
1853
c6be6cc87df4
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1852
diff
changeset
|
146 |
.. NOTE:: |
c6be6cc87df4
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1852
diff
changeset
|
147 |
You shoud check for code ``1003``:: |
c6be6cc87df4
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1852
diff
changeset
|
148 |
|
c6be6cc87df4
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1852
diff
changeset
|
149 |
MariaDB [mysql]> show warnings; |
c6be6cc87df4
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1852
diff
changeset
|
150 |
|
c6be6cc87df4
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1852
diff
changeset
|
151 |
to ensure for which query plan shown becase query may finished and new |
c6be6cc87df4
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1852
diff
changeset
|
152 |
started. |
c6be6cc87df4
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1852
diff
changeset
|
153 |
|
c6be6cc87df4
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1852
diff
changeset
|
154 |
See: |
c6be6cc87df4
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1852
diff
changeset
|
155 |
|
c6be6cc87df4
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1852
diff
changeset
|
156 |
* `SHOW EXPLAIN in MariaDB 10.0 vs EXPLAIN FOR CONNECTION in MySQL 5.7 |
c6be6cc87df4
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1852
diff
changeset
|
157 |
<http://s.petrunia.net/blog/?p=89>`_ |
c6be6cc87df4
Dump execution plan for selected process.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1852
diff
changeset
|
158 |
|
1850
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
159 |
Profiling queries. |
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
160 |
================== |
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
161 |
|
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
162 |
Enable profiling, execute query and review profiling data:: |
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
163 |
|
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
164 |
[mysql]> set profiling=1; |
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
165 |
[mysql]> select 1; |
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
166 |
[mysql]> show profile; |
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
167 |
|
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
168 |
Each profiled query results stored separately. To get list of results:: |
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
169 |
|
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
170 |
[mysql]> show profiles; |
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
171 |
|
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
172 |
To retrieve selected profiling data:: |
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
173 |
|
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
174 |
[mysql]> show profile for query 1; |
84707c692266
Monitor server execution. Profiling queries.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1849
diff
changeset
|
175 |