是否有可能以某种方式获得MySQL数据库的结构,或只是一些简单的查询表?
或者有没有别的方法,我怎么做?
是否有可能以某种方式获得MySQL数据库的结构,或只是一些简单的查询表?
或者有没有别的方法,我怎么做?
当前回答
用这个:
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 | |
+-------+-------------+-------------------+------+-----+---------+----------------+---------------------------------+---------+
选择COLUMN_NAME 从INFORMATION_SCHEMA。列 在TABLE_SCHEMA = ' bodb ' 和TABLE_NAME = ' abc ';
适用于获取所有列名
用这个:
SHOW CREATE TABLE `users`;
会给你那张表的DDL吗
DESCRIBE `users`
将列出该表中的列
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME ='products';
哪里Table_schema是数据库名称
要获得整个数据库结构的CREATE TABLE语句集,使用mysqldump:
mysqldump database_name --compact --no-data
对于单表,在mysqldump中将表名加在db名之后。使用SQL和SHOW CREATE TABLE可以得到相同的结果:
SHOW CREATE TABLE table;
如果您喜欢列列表,则使用DESCRIBE:
DESCRIBE table;