mysqlshow 用戶端對象查找工具,用來很快地查找存在哪些資料庫、資料庫中的表、表中的列或索引。和 mysql 用戶端工具很類似,不過有些特性是 mysql 用戶端工具所不具備的。
mysqlshow 的使用方法如下:
shell> mysqlshow[option] [db_name [tbl_name [col_name]]]
如果不加任何選項,預設情況下,會顯示所有資料庫。下例中顯示了目前 MySQL 中的所有資料庫:
[zzx@localhost ~]$ mysqlshow -uroot
+--------------------+
| Databases |
+--------------------+
| information_schema |
| backup |
| data |
| index |
| mysql |
| test |
| test1 |
+--------------------+
下面是 mysqlshow 的一些常用選項。
- --count(顯示資料庫和表的統計資訊)。
如果不指定資料庫,則顯示每個資料庫的名稱、表數量、記錄數量;如果指定資料庫,則顯示指定資料庫的每個表名、字段數量,記錄數量;如果指定具體資料庫中的具體表,則顯示表的字段資訊,如下例所示。
(1)不指定資料庫:
[zzx@localhost mysql]$ mysqlshow -uroot --count
+--------------------+--------+--------------+
| Databases | Tables | Total Rows |
+--------------------+--------+--------------+
| information_schema | 17 | 887 |
| bak | 0 | 0 |
| mysql | 18 | 1685 |
| test | 6 | 522 |
| test1 | 3 | 4 |
+--------------------+--------+--------------+
5 rows in set.
(2)指定資料庫:
[zzx@localhost mysql]$ mysqlshow -uroot test --count
Database: test
+--------+----------+------------+
| Tables | Columns | Total Rows |
+--------+----------+------------+
| books2 | 3 | 1 |
| dept | 2 | 512 |
| emp | 3 | 5 |
| emp1 | 3 | 3 |
| t2 | 1 | 1 |
| users2 | 2 | 0 |
+--------+----------+------------+
6 rows in set.
(3)指定資料庫和表:
[zzx@localhost mysql]$ mysqlshow -uroot test emp --count
Database: test Table: emp Rows: 5
+---------+--------------+-------------------+------+-----+---------+-------+----------
-----------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges
| Comment |
+---------+--------------+-------------------+------+-----+---------+-------+----------
-----------------------+---------+
| id | int(11) | | NO | PRI | 0 | |
select,insert,update,references | |
| name | varchar(200) | latin1_swedish_ci | YES | | | |
select,insert,update,references | |
| content | text | latin1_swedish_ci | YES | | | |
select,insert,update,references | |
+---------+--------------+-------------------+------+-----+---------+-------+----------
-----------------------+---------+
- -k –keys(顯示指定表中的所有索引)。
此選項顯示了兩部分内容,一部分是指定表的表結構,另外一部分是指定表的目前索引資訊。下例中顯示了 test 庫中表 emp 的表結構和目前索引資訊:
[zzx@localhost mysql]$ mysqlshow -uroot test emp -k
Database: test Table: emp
+---------+--------------+-------------------+------+-----+---------+-------+----------
-----------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges
| Comment |
+---------+--------------+-------------------+------+-----+---------+-------+----------
-----------------------+---------+
| id | int(11) | | NO | PRI | 0 | |
select,insert,update,references | |
| name | varchar(200) | latin1_swedish_ci | YES | | | |
select,insert,update,references | |
| content | text | latin1_swedish_ci | YES | | | |
select,insert,update,references | |
+---------+--------------+-------------------+------+-----+---------+-------+----------
-----------------------+---------+
+-------+------------+----------+--------------+-------------+-----------+-------------
+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality |
Sub_part | Packed | Null | Index_type | Comment |
+-------+------------+----------+--------------+-------------+-----------+-------------
+----------+--------+------+------------+---------+
| emp | 0 | PRIMARY | 1 | id | A | 5 |
| | | BTREE | |
+-------+------------+----------+--------------+-------------+-----------+-------------
+----------+--------+------+------------+---------+
細心的讀者可能發現,顯示的内容實際上和在 mysql 用戶端執行“show full columns from emp” 和“show index from emp”的結果完全一緻。
[zzx@localhost ~]$ mysql -uroot test -e 'show full columns from emp;show index from emp'
- -i –status(顯示表的一些狀态資訊)。
下例中顯示了 test 資料庫中 emp 表的一些狀态資訊:
[zzx@localhost mysql]$ mysqlshow -uroot test emp -i
Database: test Wildcard: emp
+------+--------+---------+------------+------+----------------+-------------+---------
--------+--------------+-----------+----------------+---------------------+-------------+---
---------+-------------------+----------+----------------+-----------------------+
| 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 |
+------+--------+---------+------------+------+----------------+-------------+---------
--------+--------------+-----------+----------------+---------------------+-------------+---
---------+-------------------+----------+----------------+-----------------------+
| emp | InnoDB | 10 | Compact | 5 | 3276 | 16384 | 0
| 0 | 0 | | 2007-08-30 06:47:22 | | |
latin1_swedish_ci | | | InnoDB free: 97280 kB |
+------+--------+---------+------------+------+----------------+-------------+---------
--------+--------------+-----------+----------------+---------------------+-------------+---
---------+-------------------+----------+----------------+-----------------------+
此指令和 mysql 用戶端執行“show table status from test like 'emp'”的結果完全一緻。
搜尋微信公衆号:TestingStudio霍格沃茲的幹貨都很硬核