Mysql Troubleshoot


Matando processos lentos - Slow Queries

mysql>show processlist;
kill "number from first col";

Vida real

mysql> show processlist;
+-----+------+-----------------+---------------+---------+------+--------------+------------------------------------------------------------------------------------------------------+
| Id  | User | Host            | db            | Command | Time | State        | Info                                                                                                 |
+-----+------+-----------------+---------------+---------+------+--------------+------------------------------------------------------------------------------------------------------+
|  39 | root | localhost       | base_database | Query   |    0 | NULL         | COMMIT                                                                                               |
|  40 | root | localhost       | base_database | Sleep   |    0 |              | NULL                                                                                                 |
| 122 | root | localhost:52939 | base_database | Query   |  501 | Sending data | INSERT INTO acid_event (sid,cid,signature,timestamp,
                              ip_src,ip_dst,ip_ |
| 123 | root | localhost:52940 | base_database | Sleep   | 2157 |              | NULL                                                                                                 |
| 124 | root | localhost:52941 | base_database | Sleep   |  349 |              | NULL                                                                                                 |
| 125 | root | localhost       | base_database | Query   |  143 | Sending data | select * from data where sid = '3-16992787'                                                          |
| 126 | root | localhost:52942 | base_database | Query   |  168 | Sending data | SELECT count(*) FROM acid_event where sid = '3'                                                      |
| 127 | root | localhost       | NULL          | Query   |    0 | NULL         | show processlist                                                                                     |
+-----+------+-----------------+---------------+---------+------+--------------+------------------------------------------------------------------------------------------------------+
8 rows in set (0.00 sec)

mysql> kill 126
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql> kill 124;
Query OK, 0 rows affected (0.00 sec)

mysql> kill 1245;
ERROR 1094 (HY000): Unknown thread id: 1245
mysql> kill 125;
Query OK, 0 rows affected (0.00 sec)

mysql> 

Tamanho de Tabelas

Todas

Para verificar o tamanho que cada tabela ocupa, use o seguinte comando:

SELECT 
     table_schema as `Database`, 
     table_name AS `Table`, 
     round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` 
FROM information_schema.TABLES 
ORDER BY (data_length + index_length) DESC;

De um Banco de dados

SELECT 
    table_name AS `Table`, 
    round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` 
FROM information_schema.TABLES 
WHERE table_schema = "$DB_NAME"
    AND table_name = "$TABLE_NAME";