目前mysql的数据库管理工具在查看字段注释时无法像PL/SQL那么方便,mysql执行select * from table后,还得转到数据表的DDL页面查看字段注释,非常不方便,因此我用python写了个脚本,可以读取mysql数据表和字段注释并自动生成查询语句。
废话不多说,直接上代码。
import pymysql class GetMysqlTableComments(): def __init__(self, host, user, password, database,port,charset): self.db = pymysql.connect(host=host, user=user, password=password, port=port, database=database, charset=charset) self.cursor = self.db.cursor() def get_tables(self, database_name): sqlstr = '' # 查询mysql表名和注释 self.cursor.execute( 'select table_name,table_comment from information_schema.TABLES where TABLE_SCHEMA=%s order by table_name', database_name) return_tables = self.cursor.fetchall() for tabledata in

为了解决在MySQL中查看字段注释不便的问题,作者编写了一个Python脚本,该脚本能读取MySQL数据表和其字段注释,并自动生成包含这些注释的查询语句。执行脚本后,会生成一个SQL文件,使得查看字段注释变得更加便捷。
9242

被折叠的 条评论
为什么被折叠?



