Mysql show命令

1、  show databases;列表當前mysql服務器上當前登錄用戶所有的數據庫列表
2、  show tables;列表當前選中數據庫下的所有表,記住使用此命令之前必須要選中一個數據庫
    mysql> use phpchengdu_test;
    Database changed
    mysql> show tables;
    +---------------------------+
    | Tables_in_phpchengdu_test |
    +---------------------------+
    | article                   |
    | comment                   |
    | newarticle                |
    | newarticle2               |
    | tt                        |
    | user                      |
    +---------------------------+
    6 rows in set (0.00 sec)

3、describe tablename;查詢指定table的結構,命令可以簡寫爲desc tablename;

      mysql> desc article;
    +---------+--------------+------+-----+---------+----------------+
    | Field   | Type         | Null | Key | Default | Extra          |
    +---------+--------------+------+-----+---------+----------------+
    | id      | int(8)       | NO   | PRI | NULL    | auto_increment |
    | title   | varchar(255) | NO   | MUL | NULL    |                |
    | content | text         | NO   |     | NULL    |                |
    | time    | datetime     | NO   |     | NULL    |                |
    | author  | varchar(60)  | NO   |     | NULL    |                |
    | tag     | varchar(255) | YES  |     | NULL    |                |
    +---------+--------------+------+-----+---------+----------------+
    6 rows in set (0.07 sec)

          mysql> describe article;
    +---------+--------------+------+-----+---------+----------------+
    | Field   | Type         | Null | Key | Default | Extra          |
    +---------+--------------+------+-----+---------+----------------+
    | id      | int(8)       | NO   | PRI | NULL    | auto_increment |
    | title   | varchar(255) | NO   | MUL | NULL    |                |
    | content | text         | NO   |     | NULL    |                |
    | time    | datetime     | NO   |     | NULL    |                |
    | author  | varchar(60)  | NO   |     | NULL    |                |
    | tag     | varchar(255) | YES  |     | NULL    |                |
    +---------+--------------+------+-----+---------+----------------+
    6 rows in set (0.01 sec)

4、show create table tablename;查看指定表的原始創建語句

    mysql> show create table article;
    +---------+---------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------+
    | Table   | Create Table



              |
    +---------+---------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------+
    | article | CREATE TABLE `article` (
      `id` int(8) NOT NULL auto_increment,
      `title` varchar(255) NOT NULL,
      `content` text NOT NULL,
      `time` datetime NOT NULL,
      `author` varchar(60) NOT NULL,
      `tag` varchar(255) default NULL,
      PRIMARY KEY  (`id`),
      KEY `title` (`title`)
    ) ENGINE=MyISAM AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 |
    +---------+---------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------+
    1 row in set (0.01 sec)


5、show index from tablename;查看錶的索引
    mysql> show index from article;
    +---------+------------+----------+--------------+-------------+-----------+----
    ---------+----------+--------+------+------------+---------+
    | Table   | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Car
    dinality | Sub_part | Packed | Null | Index_type | Comment |
    +---------+------------+----------+--------------+-------------+-----------+----
    ---------+----------+--------+------+------------+---------+
    | article |          0 | PRIMARY  |            1 | id          | A         |
          10 |     NULL | NULL   |      | BTREE      |         |
    | article |          1 | title    |            1 | title       | A         |
          10 |     NULL | NULL   |      | BTREE      |         |
    +---------+------------+----------+--------------+-------------+-----------+----
    ---------+----------+--------+------+------------+---------+
    2 rows in set (0.00 sec)
6、show engines;查看可用的表類型
    mysql> show engines;
    +------------+---------+--------------------------------------------------------
    --------+
    | Engine     | Support | Comment
        |
    +------------+---------+--------------------------------------------------------
    --------+
    | MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance
        |
    | MEMORY     | YES     | Hash based, stored in memory, useful for temporary tabl
    es      |
    | InnoDB     | YES     | Supports transactions, row-level locking, and foreign k
    eys     |
    | BerkeleyDB | NO      | Supports transactions and page-level locking
        |
    | BLACKHOLE  | YES     | /dev/null storage engine (anything you write to it disa
    ppears) |
    | EXAMPLE    | NO      | Example storage engine
        |
    | ARCHIVE    | YES     | Archive storage engine
        |
    | CSV        | NO      | CSV storage engine
        |
    | ndbcluster | NO      | Clustered, fault-tolerant, memory-based tables
        |
    | FEDERATED  | YES     | Federated MySQL storage engine
        |
    | MRG_MYISAM | YES     | Collection of identical MyISAM tables
        |
    | ISAM       | NO      | Obsolete storage engine
        |
    +------------+---------+--------------------------------------------------------
    --------+
    12 rows in set (0.00 sec)
7、show processlist;顯示連接到當前數據庫服務器的活動連接的相關信息
    mysql> show processlist;
    +----+------+-----------------+-----------------+---------+------+-------+------
    ------------+
    | Id | User | Host            | db              | Command | Time | State | Info
            |
    +----+------+-----------------+-----------------+---------+------+-------+------
    ------------+
    | 14 | root | localhost:53898 | phpchengdu_test | Query   |    0 | NULL  | show
    processlist |
    +----+------+-----------------+-----------------+---------+------+-------+------
    ------------+
    1 row in set (0.01 sec)
8、show errors;顯示當前數據庫服務器上發生的錯誤信息
9、show warnings;顯示當前數據庫服務器上發生的警告信息
    mysql> show errors;
    Empty set (0.00 sec)
    mysql> show warnings;
    +-------+------+----------------------------------------------------------------
    --------------------------------------------------------------------------------
    -----------------+
    | Level | Code | Message

             |
    +-------+------+----------------------------------------------------------------
    --------------------------------------------------------------------------------
    -----------------+
    | Error | 1064 | You have an error in your SQL syntax; check the manual that cor
    responds to your MySQL server version for the right syntax to use near 'shoe war
    nings' at line 1 |
    +-------+------+----------------------------------------------------------------
    --------------------------------------------------------------------------------
    -----------------+
    1 row in set (0.00 sec)
10、show status;顯示當前服務器上的狀態信息,比如服務器啓動時間、當前正在執行的查詢數量、當前的併發連接數等,此處可以通過like 關鍵字只匹配某些執行信息
    mysql> show status like 't%';
    +-----------------------+-------+
    | Variable_name         | Value |
    +-----------------------+-------+
    | Table_locks_immediate | 31    |
    | Table_locks_waited    | 0     |
    | Tc_log_max_pages_used | 0     |
    | Tc_log_page_size      | 0     |
    | Tc_log_page_waits     | 0     |
    | Threads_cached        | 0     |
    | Threads_connected     | 1     |
    | Threads_created       | 14    |
    | Threads_running       | 1     |
    +-----------------------+-------+
    9 rows in set (0.00 sec)
11、show table status;顯示選中數據庫中表的詳細信息,仍可使用like來匹配某些表
    mysql> show table status like 'article%';
    +---------+--------+---------+------------+------+----------------+-------------
    +-----------------+--------------+-----------+----------------+-----------------
    ----+---------------------+---------------------+-----------------+----------+--
    --------------+---------+
    | 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 | C
    reate_options | Comment |
    +---------+--------+---------+------------+------+----------------+-------------
    +-----------------+--------------+-----------+----------------+-----------------
    ----+---------------------+---------------------+-----------------+----------+--
    --------------+---------+
    | article | MyISAM |      10 | Dynamic    |   10 |             55 |         556
    | 281474976710655 |         6144 |         0 |             21 | 2009-11-28 17:20
    :48 | 2009-11-28 17:20:50 | 2009-11-28 17:20:48 | utf8_general_ci |     NULL |
              |         |
    +---------+--------+---------+------------+------+----------------+-------------
    +-----------------+--------------+-----------+----------------+-----------------
    ----+---------------------+---------------------+-----------------+----------+--
    --------------+---------+
    1 row in set (0.00 sec)
12、show character set;顯示當前服務器上可用的編碼列表

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章