python代码获取mysql字段名和注释

# coding=utf-8
import pymysql


def get_mysql_zi_duan():
    conn = pymysql.connect(host='192.168.', port=3306, user='hs', 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_xingyun' and table_name = 'api_ind_guan_yi_s_d'")
    all_info = cursor01.fetchall()  # 数据库字段名和注释
    # print(all_info)
    zi_duan_ming = []
    zhushi = []
    for data in all_info:
        zi_duan_ming.append(data[0])
        zhushi.append(data[1])
        # print(data[0])
    print(str(zi_duan_ming).replace('[','').replace(']','').replace("'",''))
    print(zhushi)

    cursor01.close()
    conn.close()


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

你可能感兴趣的:(python,数据分析及挖掘,爬虫,my,python)