如何从 mysql 表访问表注释?
如何从 mysql 表中获取只是表注释?我尝试了以下方法,但由于各种原因它们没有工作。我想弄清楚如何获取字符串“我的评论”(最好通过 perl =)
有帮助吗?
-- 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 |
+------+--------+---------+------------+------+----------------+---------------+
和
SHOW CREATE TABLE foo;
+-------+------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------+
| fooo | CREATE TABLE `fooo` (`id` int(11) NOT NULL PRIMARY KEY) COMMENT='my comment' |
+-------+------------------------------------------------------------------------------+
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 =)
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' |
+-------+------------------------------------------------------------------------------+
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基于OMG Ponies的答案,但使用
INFORMATION_SCHEMA.TABLES
而不是INFORMATION_SCHEMA.COLUMNS
。当我在网上浏览时,我所能找到的只是关于专栏评论的信息,但从来没有关于表格的信息。这是获取表评论的方法。Based on the answer by OMG Ponies, but using
INFORMATION_SCHEMA.TABLES
instead ofINFORMATION_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.如果你不想在查询中同时使用数据库名和表名,你可以使用 :
,然后选取结果的“Comment”键(你必须使用像 php 中的 mysqli_fetch_assoc() 这样的关联函数)。
If you don't want to have both database name and table name in the query, you can use :
and then pick up the "Comment" key of the result (you have to use an associative function like mysqli_fetch_assoc() in php).