Environment
Code
#encoding: utf-8#author: walker#date: 2018-07-26#summary: Printing MySQL/MariaDB All library names, table names, and field names Import pymysqlimport pprint dbhost = r ' 127.0.0.1 ' dbport = 3306dbuser = ' root ' dbpwd = ' password ' # ignore system library ignoredb = {' Information_ Schema ', ' mysql ', ' performance_schema ', ' sys '} # processing a database def proconedb (dbName): print (' ************ use %s ************ ' % dbname) conndb = pymysql.connect (host=dbhost, port=DBPort, user=dbuser, passwd=DBPwd, db= dbname, charset= ' UTF8MB4 ') cur = conndb.cursor () sql = ' show tables; ' cur.execute (SQL) rowlist = cur.fetchall () tablelist = list () for row in rowlist:&nbsP; tablelist.append (Row[0]) print (' TableList (% d): \n%s\n ' % (Len (tablelist), pprint.pformat (tablelist, indent=4))) # Process each table for tabName in Tablelist: print (' table %s .. ' % tabName) sql = "select column_name from Information_schema.columns where table_schema= '%s ' and table_name= '%s '; " sql = sql % (dbname, tabname) cur.execute (SQL) Rowlist = cur.fetchall () fieldlist = list () for row in rowlist: Fieldlist.append (Row[0]) print (' FieldList (%d): \n%s\n ' % (Len (FieldList), pprint.pformat (fieldlist, indent=4)) cur.close () conndb.close () # process all databases def Procalldb (): conndb = pymysql.connect (host=dbhost, port=DBPort, user=DBUser, &nbsP; passwd=dbpwd , charset= ' utf8mb4 ') Cur = conndb.cursor () sql = "show databases;" print (' Input sql: ' + sql) cur.execute (SQL) rowlist = cur.fetchall () cur.close () conndb.close ()          DBLIST =&NBsp;list () for row in rowList: dblist.append (Row[0]) print (' DBList (%d): \n%s\n ' % (len (dblist), Pprint.pformat (dblist, indent=4)) for dbname in dblist: if dbname in ignoredb: continue proconedb (DbName) if __name__ == ' __ Main__ ': procalldb ()
Walker * * *
Print all library names, table names, and field names for mysql/mariadb with Pymysql