Skip to content

Commit e917b31

Browse files
authored
Merge pull request #2 from renecannao/patch-1
Create intro_commands.md
2 parents 9b09b83 + f33a11a commit e917b31

1 file changed

Lines changed: 393 additions & 0 deletions

File tree

intro_commands.md

Lines changed: 393 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,393 @@
1+
2+
### Installation
3+
ProxySQL binaries are available from https://github.com/sysown/proxysql/releases.
4+
Just download and use the package manager to install it.
5+
Ex:
6+
```bash
7+
wget https://github.com/sysown/proxysql/releases/download/v1.3.5/proxysql_1.3.5-ubuntu14_amd64.deb
8+
dpkg -i proxysql_1.3.5-ubuntu14_amd64.deb
9+
```
10+
11+
### Service management
12+
Once the software is installed, you can use `service` to start or stop it.
13+
#### Start:
14+
```bash
15+
service proxysql start
16+
```
17+
#### Stop:
18+
```bash
19+
service proxysql stop
20+
```
21+
22+
23+
24+
### Check version
25+
```bash
26+
$ proxysql --version
27+
```
28+
```bash
29+
ProxySQL version 1.3.5-0-g10bf524, codename Truls
30+
```
31+
A debug version has `_DEBUG` in its version string.
32+
It is slower than non-debug version, but easier to debug in case of failures.
33+
34+
* check processes running:
35+
```bash
36+
ps aux | grep proxysql | grep -v grep
37+
root 4261 0.0 0.1 31760 3080 ? S 22:49 0:00 proxysql -c /etc/proxysql.cnf -D /var/lib/proxysql
38+
root 4262 3.0 0.3 171628 6396 ? Sl 22:49 0:00 proxysql -c /etc/proxysql.cnf -D /var/lib/proxysql
39+
```
40+
Why two processes?
41+
42+
43+
* check which sockets are open:
44+
```bash
45+
netstat -nap | grep proxysql
46+
```
47+
Output:
48+
```bash
49+
tcp 0 0 127.0.0.1:6032 0.0.0.0:* LISTEN 4262/proxysql
50+
tcp 0 0 0.0.0.0:6033 0.0.0.0:* LISTEN 4262/proxysql
51+
unix 2 [ ACC ] STREAM LISTENING 8197 4262/proxysql /tmp/proxysql.sock
52+
unix 2 [ ACC ] STREAM LISTENING 8062 4262/proxysql /tmp/proxysql_admin.sock
53+
```
54+
55+
* check opened file
56+
```bash
57+
lsof -n -p 4261
58+
lsof -n -p 3262
59+
```
60+
61+
Why 2 processes? Angel process and real process.
62+
63+
64+
## Admin Interface
65+
#### login as `admin`
66+
Use a mysql client and connect using standard credentials and endpoint. Ex:
67+
```bash
68+
mysql -u admin -padmin -h 127.0.0.1 -P6032 --prompt='Admin> '
69+
```
70+
Output:
71+
```
72+
Warning: Using a password on the command line interface can be insecure.
73+
Welcome to the MySQL monitor. Commands end with ; or \g.
74+
Your MySQL connection id is 4
75+
Server version: 5.5.30 (ProxySQL Admin Module)
76+
77+
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
78+
79+
Oracle is a registered trademark of Oracle Corporation and/or its
80+
affiliates. Other names may be trademarks of their respective
81+
owners.
82+
83+
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
84+
85+
Admin>
86+
```
87+
88+
#### check version
89+
```mysql
90+
Admin> SELECT @@version;
91+
+------------------+
92+
| @@version |
93+
+------------------+
94+
| 1.3.5-0-g10bf524 |
95+
+------------------+
96+
1 row in set (0.00 sec)
97+
```
98+
99+
#### list available schemas and tables
100+
```mysql
101+
Admin> SHOW DATABASES;
102+
+-----+---------+-------------------------------+
103+
| seq | name | file |
104+
+-----+---------+-------------------------------+
105+
| 0 | main | |
106+
| 2 | disk | /var/lib/proxysql/proxysql.db |
107+
| 3 | stats | |
108+
| 4 | monitor | |
109+
+-----+---------+-------------------------------+
110+
4 rows in set (0.00 sec)
111+
```
112+
```mysql
113+
Admin> SHOW TABLES FROM main;
114+
+--------------------------------------+
115+
| tables |
116+
+--------------------------------------+
117+
| global_variables |
118+
| mysql_collations |
119+
| mysql_query_rules |
120+
| mysql_replication_hostgroups |
121+
| mysql_servers |
122+
| mysql_users |
123+
| runtime_global_variables |
124+
| runtime_mysql_query_rules |
125+
| runtime_mysql_replication_hostgroups |
126+
| runtime_mysql_servers |
127+
| runtime_mysql_users |
128+
| runtime_scheduler |
129+
| scheduler |
130+
+--------------------------------------+
131+
13 rows in set (0.00 sec)
132+
```
133+
```mysql
134+
Admin> SHOW TABLES LIKE 'runtime%';
135+
+--------------------------------------+
136+
| tables |
137+
+--------------------------------------+
138+
| runtime_mysql_servers |
139+
| runtime_mysql_users |
140+
| runtime_mysql_replication_hostgroups |
141+
| runtime_mysql_query_rules |
142+
| runtime_global_variables |
143+
| runtime_scheduler |
144+
+--------------------------------------+
145+
6 rows in set (0.00 sec)
146+
```
147+
```mysql
148+
Admin> SHOW TABLES FROM disk;
149+
+------------------------------+
150+
| tables |
151+
+------------------------------+
152+
| global_variables |
153+
| mysql_collations |
154+
| mysql_query_rules |
155+
| mysql_replication_hostgroups |
156+
| mysql_servers |
157+
| mysql_users |
158+
| scheduler |
159+
+------------------------------+
160+
7 rows in set (0.00 sec)
161+
```
162+
```mysql
163+
Admin> SHOW TABLES FROM stats;
164+
+--------------------------------+
165+
| tables |
166+
+--------------------------------+
167+
| global_variables |
168+
| stats_mysql_commands_counters |
169+
| stats_mysql_connection_pool |
170+
| stats_mysql_global |
171+
| stats_mysql_processlist |
172+
| stats_mysql_query_digest |
173+
| stats_mysql_query_digest_reset |
174+
| stats_mysql_query_rules |
175+
+--------------------------------+
176+
8 rows in set (0.00 sec)
177+
```
178+
```mysql
179+
Admin> SHOW TABLES FROM monitor;
180+
+----------------------------------+
181+
| tables |
182+
+----------------------------------+
183+
| mysql_server_connect |
184+
| mysql_server_connect_log |
185+
| mysql_server_ping |
186+
| mysql_server_ping_log |
187+
| mysql_server_read_only_log |
188+
| mysql_server_replication_lag_log |
189+
+----------------------------------+
190+
6 rows in set (0.00 sec)
191+
```
192+
This is NOT really a MySQL server. Not all commands are supported.
193+
For example, `USE` is not supported.
194+
For example:
195+
```mysql
196+
USE main;
197+
SHOW TABLES;
198+
USE stats;
199+
SHOW TABLES;
200+
```
201+
202+
## Global variables
203+
```mysql
204+
Admin> SHOW CREATE TABLE global_variables\G
205+
*************************** 1. row ***************************
206+
table: global_variables
207+
Create Table: CREATE TABLE global_variables (
208+
variable_name VARCHAR NOT NULL PRIMARY KEY,
209+
variable_value VARCHAR NOT NULL)
210+
1 row in set (0.01 sec)
211+
```
212+
213+
* list all variables
214+
```mysql
215+
SELECT * FROM global_variables;
216+
```
217+
218+
* list all Admin related variables
219+
```mysql
220+
SELECT * FROM global_variables WHERE variable_name LIKE 'admin-%';
221+
```
222+
223+
* list all MySQL related variables
224+
```mysql
225+
SELECT * FROM global_variables WHERE variable_name LIKE 'mysql-%';
226+
```
227+
228+
* list all variables related to MySQL Monitor
229+
```mysql
230+
SELECT * FROM global_variables WHERE variable_name LIKE 'mysql-%monitor%' ORDER BY variable_name;
231+
```
232+
233+
## How to change variable?
234+
235+
* method #1
236+
```mysql
237+
Admin> UPDATE global_variables SET variable_value=1000 WHERE variable_name='mysql-monitor_ping_interval';
238+
Query OK, 1 row affected (0.01 sec)
239+
```
240+
241+
* method #2
242+
```mysql
243+
Admin> SET mysql-monitor_ping_interval=1000;
244+
Query OK, 1 row affected (0.00 sec)
245+
```
246+
247+
* Some exception:
248+
```mysql
249+
Admin> SET mysql-init_connect='SET wait_timeout=100';
250+
ERROR 1045 (#2800): ERROR: Global variable 'mysql-init_connect' is not configurable using SET command. You must run UPDATE global_variables
251+
Admin> UPDATE global_variables SET variable_value="SET wait_timeout=100" WHERE variable_name='mysql-init_connect';
252+
Query OK, 1 row affected (0.01 sec)
253+
```
254+
255+
256+
## runtime variables
257+
```mysql
258+
Admin> SELECT * FROM runtime_global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%' ORDER BY variable_name;
259+
+---------------------------------+----------------+
260+
| variable_name | variable_value |
261+
+---------------------------------+----------------+
262+
| mysql-monitor_ping_interval | 10000 |
263+
| mysql-monitor_ping_max_failures | 3 |
264+
| mysql-monitor_ping_timeout | 1000 |
265+
+---------------------------------+----------------+
266+
3 rows in set (0.01 sec)
267+
```
268+
Why aren't variables loaded at runtime immediately?
269+
See [wiki](https://github.com/sysown/proxysql/wiki/Multi-layer-configuration-system)
270+
271+
- allows to verify changes before applying them.
272+
- all changes are loaded atomically.
273+
- allows rollback in case of mistakes (`UPDATE global_variables SET variable_value=2000` ... without `WHERE`).
274+
275+
```mysql
276+
SELECT * FROM global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
277+
SELECT * FROM disk.global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
278+
SELECT * FROM runtime_global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
279+
LOAD MYSQL VARIABLES TO RUNTIME;
280+
SELECT * FROM global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
281+
SELECT * FROM disk.global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
282+
SELECT * FROM runtime_global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
283+
SAVE MYSQL VARIABLES TO DISK;
284+
SET mysql-monitor_ping_interval=100000;
285+
SELECT * FROM global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
286+
SELECT * FROM disk.global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
287+
SELECT * FROM runtime_global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
288+
SAVE MYSQL VARIABLES FROM RUNTIME;
289+
SELECT * FROM global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
290+
SELECT * FROM disk.global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
291+
SELECT * FROM runtime_global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
292+
LOAD MYSQL VARIABLES FROM DISK;
293+
SELECT * FROM global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
294+
SELECT * FROM disk.global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
295+
SELECT * FROM runtime_global_variables WHERE variable_name LIKE 'mysql-%monitor%ping%val' ORDER BY variable_name;
296+
```
297+
298+
## MySQL Servers : backends
299+
```mysql
300+
Admin> SELECT * FROM mysql_servers;
301+
Empty set (0.00 sec)
302+
303+
Admin> SHOW CREATE TABLE mysql_servers\G
304+
*************************** 1. row ***************************
305+
table: mysql_servers
306+
Create Table: CREATE TABLE mysql_servers (
307+
hostgroup_id INT NOT NULL DEFAULT 0,
308+
hostname VARCHAR NOT NULL,
309+
port INT NOT NULL DEFAULT 3306,
310+
status VARCHAR CHECK (UPPER(status) IN ('ONLINE','SHUNNED','OFFLINE_SOFT', 'OFFLINE_HARD')) NOT NULL DEFAULT 'ONLINE',
311+
weight INT CHECK (weight >= 0) NOT NULL DEFAULT 1,
312+
compression INT CHECK (compression >=0 AND compression <= 102400) NOT NULL DEFAULT 0,
313+
max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 1000,
314+
max_replication_lag INT CHECK (max_replication_lag >= 0 AND max_replication_lag <= 126144000) NOT NULL DEFAULT 0,
315+
use_ssl INT CHECK (use_ssl IN(0,1)) NOT NULL DEFAULT 0,
316+
max_latency_ms INT UNSIGNED CHECK (max_latency_ms>=0) NOT NULL DEFAULT 0,
317+
comment VARCHAR NOT NULL DEFAULT '',
318+
PRIMARY KEY (hostgroup_id, hostname, port) )
319+
1 row in set (0.00 sec)
320+
```
321+
```mysql
322+
Admin> SELECT * FROM mysql_servers;
323+
Empty set (0.00 sec)
324+
325+
Admin> INSERT INTO mysql_servers (hostgroup_id, hostname, port, weight) VALUES (0,'127.0.0.1',3306,10);
326+
Query OK, 1 row affected (0.00 sec)
327+
328+
Admin> SELECT * FROM mysql_servers\G
329+
*************************** 1. row ***************************
330+
hostgroup_id: 0
331+
hostname: 127.0.0.1
332+
port: 3306
333+
status: ONLINE
334+
weight: 10
335+
compression: 0
336+
max_connections: 1000
337+
max_replication_lag: 0
338+
use_ssl: 0
339+
max_latency_ms: 0
340+
comment:
341+
1 row in set (0.00 sec)
342+
343+
Admin> SELECT * FROM runtime_mysql_servers;
344+
Empty set (0.00 sec)
345+
```
346+
```mysql
347+
LOAD MYSQL SERVERS TO RUNTIME;
348+
SAVE MYSQL SERVERS TO DISK;
349+
LOAD MYSQL SERVERS FROM DISK;
350+
SAVE MYSQL SERVERS FROM RUNTIME;
351+
```
352+
```mysql
353+
Admin> SHOW CREATE TABLE mysql_users\G
354+
*************************** 1. row ***************************
355+
table: mysql_users
356+
Create Table: CREATE TABLE mysql_users (
357+
username VARCHAR NOT NULL,
358+
password VARCHAR,
359+
active INT CHECK (active IN (0,1)) NOT NULL DEFAULT 1,
360+
use_ssl INT CHECK (use_ssl IN (0,1)) NOT NULL DEFAULT 0,
361+
default_hostgroup INT NOT NULL DEFAULT 0,
362+
default_schema VARCHAR,
363+
schema_locked INT CHECK (schema_locked IN (0,1)) NOT NULL DEFAULT 0,
364+
transaction_persistent INT CHECK (transaction_persistent IN (0,1)) NOT NULL DEFAULT 0,
365+
fast_forward INT CHECK (fast_forward IN (0,1)) NOT NULL DEFAULT 0,
366+
backend INT CHECK (backend IN (0,1)) NOT NULL DEFAULT 1,
367+
frontend INT CHECK (frontend IN (0,1)) NOT NULL DEFAULT 1,
368+
max_connections INT CHECK (max_connections >=0) NOT NULL DEFAULT 10000,
369+
PRIMARY KEY (username, backend),
370+
UNIQUE (username, frontend))
371+
1 row in set (0.00 sec)
372+
```
373+
374+
## update config file
375+
#### (and why doesn't work)
376+
377+
```bash
378+
vi /etc/proxysql.cnf
379+
service proxysql restart
380+
```
381+
```mysql
382+
Admin> SHOW VARIABLES LIKE 'mysql-default_query_timeout';
383+
```
384+
385+
386+
### Upgrade
387+
Install the new package and restart.
388+
Ex:
389+
```bash
390+
wget https://github.com/sysown/proxysql/releases/download/v1.3.6/proxysql_1.3.6-ubuntu14_amd64.deb
391+
dpkg -i proxysql_1.3.6-ubuntu14_amd64.deb
392+
service proxysql restart
393+
```

0 commit comments

Comments
 (0)