MySQL ottenere informazioni sulle tabelle di un database

06 settembre 2012

Per ottenere un elenco delle tabelle non temporanee presenti in un database si può usare il comando SHOW TABLES:
mysql> use testdb
Database changed
mysql>SHOW TABLES;
+-----------------------+
| Tables_in_testdb      |
+-----------------------+
| tabella_1             |
| tabella_2             |
| tabella_3             |
+-----------------------+
3 rows in set (0.00 sec)
Se invece si vogliono maggiori informazioni come l'engine (MyIsam, InnoDB,...) delle tabelle o la lunghezza media delle righe basta usare SHOW TABLE STATUS:
mysql> SHOW TABLE STATUS;
+-----------+--------+---------+------------+------+----------------+-------------+-------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+--------------------+---------+
| Name      | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length   | Index_length | Data_free | Auto_increment | Create_time         | Update_time         | Check_time | Collation       | Checksum | Create_options     | Comment |
+-----------+--------+---------+------------+------+----------------+-------------+-------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+--------------------+---------+
| tabella_1 | MyISAM |      10 | Dynamic    |    8 |             44 |         352 |   281474976710655 |         2048 |         0 |              9 | 2013-09-06 11:44:48 | 2013-09-06 11:44:48 | NULL       | utf8_general_ci |     NULL |                    |         |
| tabella_2 | MyISAM |      10 | Dynamic    |    3 |             57 |         172 |   281474976710655 |         2048 |         0 |              5 | 2013-07-09 15:07:46 | 2013-08-21 09:40:15 | NULL       | utf8_general_ci |     NULL |                    |         |
| tabella_3 | MyISAM |      10 | Dynamic    |   13 |             74 |         964 |   281474976710655 |         2048 |         0 |             16 | 2013-07-10 19:24:37 | 2013-08-23 16:40:55 | NULL       | utf8_general_ci |     NULL |                    |         |
+-----------+--------+---------+------------+------+----------------+-------------+-------------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+--------------------+--------
3 rows in set (0.00 sec)
Analoghe informazioni si possono ottenere con il comando mysqlshow:
[root]# mysqlshow -uroot -pmiapass testdb
[root]# mysqlshow --status -uroot -pmiapass testdb