是否有可能以某种方式获得MySQL数据库的结构,或只是一些简单的查询表?

或者有没有别的方法,我怎么做?


当前回答

第一个答案的变化,我觉得很有用

打开你的命令提示符并输入(你不需要登录到你的mysql服务器)

mysqldump -hlocalhost -u<root> -p<password>  <dbname>  --compact --no-data > </path_to_mydump/>mysql.dmp

其他回答

我觉得你想要的是描述

DESCRIBE table;

您还可以使用SHOW TABLES

SHOW TABLES;

获取数据库中的表列表。

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME ='products'; 

哪里Table_schema是数据库名称

您可以选择下面的任何一个命令。所有这些或多或少都是一样的:

创建表table_name

DESC TABLE_NAME;

显示table_name中的所有列;(用于列属性)

解释TABLE_NAME;

描述TABLE_NAME;

用这个:

SHOW CREATE TABLE `users`;

会给你那张表的DDL吗

DESCRIBE `users`

将列出该表中的列

在下面的例子中,

Playground是数据库名,equipment是表名

另一种方法是使用SHOW-COLUMNS:5.5(也适用于5.5>)

$ mysql -uroot -p<password> -h<host> -P<port> -e \
    "SHOW COLUMNS FROM playground.equipment"

输出:

mysql: [Warning] Using a password on the command line interface can be insecure.
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| type  | varchar(50) | YES  |     | NULL    |                |
| quant | int(11)     | YES  |     | NULL    |                |
| color | varchar(25) | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+

你也可以像下面这样使用mysqlshow-client(也适用于5.5>):

$ mysqlshow -uroot -p<password> -h<host> -P<port> \
    playground equipment

输出:

mysqlshow: [Warning] Using a password on the command line interface can be insecure.
Database: playground  Table: equipment
+-------+-------------+-------------------+------+-----+---------+----------------+---------------------------------+---------+
| Field | Type        | Collation         | Null | Key | Default | Extra          | Privileges                      | Comment |
+-------+-------------+-------------------+------+-----+---------+----------------+---------------------------------+---------+
| id    | int(11)     |                   | NO   | PRI |         | auto_increment | select,insert,update,references |         |
| type  | varchar(50) | latin1_swedish_ci | YES  |     |         |                | select,insert,update,references |         |
| quant | int(11)     |                   | YES  |     |         |                | select,insert,update,references |         |
| color | varchar(25) | latin1_swedish_ci | YES  |     |         |                | select,insert,update,references |         |
+-------+-------------+-------------------+------+-----+---------+----------------+---------------------------------+---------+