How can I get just the table comment from a mysql table? I tried the following, but they didn't work for various reasons. I want to figure out how to get just the string 'my comment' (ideally via perl =)
如何从mysql表中获得表注释?我尝试了下面的方法,但是由于各种原因,它们都不起作用。我想知道如何获得字符串“my comment”(最好是通过perl =)
Any help?
任何帮助吗?
-- Abbreviated output for convenience.
SHOW TABLE STATUS WHERE Name="foo"
+------+--------+---------+------------+------+----------------+---------------+
| Name | Engine | Version | Row_format | Rows | Create_options | Comment |
+------+--------+---------+------------+------+----------------+---------------+
| foo | MyISAM | 10 | Fixed | 0 | | my comment |
+------+--------+---------+------------+------+----------------+---------------+
and
和
SHOW CREATE TABLE foo;
+-------+------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------+
| fooo | CREATE TABLE `fooo` (`id` int(11) NOT NULL PRIMARY KEY) COMMENT='my comment' |
+-------+------------------------------------------------------------------------------+
2 个解决方案
#1
28
Based on the answer by OMG Ponies, but using INFORMATION_SCHEMA.TABLES
instead of INFORMATION_SCHEMA.COLUMNS
. When looking around on the web, all I could find was info on the columns' comments, but never on the table's. This is how to get a table's comment.
基于OMG小马的回答,但是使用INFORMATION_SCHEMA。表而不是INFORMATION_SCHEMA.COLUMNS。当我在网上搜索时,我能找到的只是列上的评论,而不是表格上的。这是获取表注释的方法。
SELECT table_comment
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema='my_cool_database'
AND table_name='user_skill';
+--------------------------+
| table_comment |
+--------------------------+
| my awesome comment |
+--------------------------+
#2
1
If you don't want to have both database name and table name in the query, you can use :
如果不希望查询中同时包含数据库名和表名,可以使用:
SHOW TABLE STATUS WHERE Name='table_name';
and then pick up the "Comment" key of the result (you have to use an associative command like mysqli_fetch_assoc() in php).
然后获取结果的“Comment”键(必须在php中使用mysqli_fetch_assoc()之类的关联命令)。
#1
28
Based on the answer by OMG Ponies, but using INFORMATION_SCHEMA.TABLES
instead of INFORMATION_SCHEMA.COLUMNS
. When looking around on the web, all I could find was info on the columns' comments, but never on the table's. This is how to get a table's comment.
基于OMG小马的回答,但是使用INFORMATION_SCHEMA。表而不是INFORMATION_SCHEMA.COLUMNS。当我在网上搜索时,我能找到的只是列上的评论,而不是表格上的。这是获取表注释的方法。
SELECT table_comment
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema='my_cool_database'
AND table_name='user_skill';
+--------------------------+
| table_comment |
+--------------------------+
| my awesome comment |
+--------------------------+
#2
1
If you don't want to have both database name and table name in the query, you can use :
如果不希望查询中同时包含数据库名和表名,可以使用:
SHOW TABLE STATUS WHERE Name='table_name';
and then pick up the "Comment" key of the result (you have to use an associative command like mysqli_fetch_assoc() in php).
然后获取结果的“Comment”键(必须在php中使用mysqli_fetch_assoc()之类的关联命令)。