代码查询数据库数据表的所有字段和对应注释

# coding=utf-8
import pymysql


def get_mysql_zi_duan():
    conn = pymysql.connect(host='192.16.00.0', port=3306, user='h', passwd='xi', db='db_x', charset='utf8')
    cursor01 = conn.cursor()
    cursor01.execute(
        "select column_name, column_comment from information_schema.columns where table_schema ='db_x' and table_name = 'api_lingo_all_data'")
    all_info = cursor01.fetchall()  # 数据库字段名和注释
    print(all_info)
    zi_duan_ming = []
    for data in all_info:
        zi_duan_ming.append(data[0])
    print(str(zi_duan_ming).replace('[','').replace(']',''))

    cursor01.close()
    conn.close()
    

if __name__ == '__main__':
    # 获取一个表的 所有字段名
    get_mysql_zi_duan()

猜你喜欢

转载自blog.csdn.net/l1159015838/article/details/80970895