Open1

MySQL クエリメモ

shuntagamishuntagami
mysql> show full processlist;
+-----+------+-----------+-------+---------+------+----------+-----------------------+
| Id  | User | Host      | db    | Command | Time | State    | Info                  |
+-----+------+-----------+-------+---------+------+----------+-----------------------+
| 200 | root | localhost | mysql | Query   |    0 | starting | show full processlist |
| 201 | root | localhost | mysql | Sleep   |   10 |          | NULL                  |
+-----+------+-----------+-------+---------+------+----------+-----------------------+]

~秒以上かかるクエリを発見したい

mysql> SET GLOBAL slow_query_log = 'ON';
Query OK, 0 rows affected (0.06 sec)

mysql> show variables like "slow_query_log";
+----------------+-------+
| Variable_name  | Value |
+----------------+-------+
| slow_query_log | ON    |
+----------------+-------+

mysql> show variables like "long_query_time";
+-----------------+-----------+
| Variable_name   | Value     |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+

mysql> SET long_query_time = 1;

mysql> select * from mysql.slow_log;

コネクション数

mysql> show variables like "max_connections";
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151   |
+-----------------+-------+
1 row in set (0.03 sec)

mysql> set global max_connections = 1000;

使われてないindex

select * from sys.schema_unused_indexes;