In [1]:
import mysql.connector as mysql

def query1():
    db = mysql.connect(
        host="localhost",
        database="raj",
        user="raj",
        passwd="r123",
        auth_plugin='mysql_native_password'
      )
    query = "select bcode,bname from BUILDING "
    cursor = db.cursor()
    cursor.execute(query)
    records = cursor.fetchall()
    if len(records) == 0:
        print('No Buildings')
    else:
        bldgs = []
        for record in records:
            bldgs.append({'bldg':record[0], 'bname':record[1]})
        print(bldgs)

query1()
[{'bldg': '25PP', 'bname': '25 Park Place'}, {'bldg': 'ADHOLD', 'bname': 'Adherhold Learning Center'}, {'bldg': 'ARTS', 'bname': 'Art & Humanities Bldg'}, {'bldg': 'CLSO', 'bname': 'Classroom South Bldg'}, {'bldg': 'COE', 'bname': 'College of Education'}, {'bldg': 'COMMON', 'bname': 'University Commons'}, {'bldg': 'KELL', 'bname': 'Kell Hall'}, {'bldg': 'LANGDL', 'bname': 'Langdale Hall'}, {'bldg': 'LIBSO', 'bname': 'Library South'}, {'bldg': 'NSC', 'bname': 'Natural Science Center'}, {'bldg': 'PIED', 'bname': 'Piedmont Hall'}, {'bldg': 'PSC', 'bname': 'Petit Science Building'}, {'bldg': 'SPARKS', 'bname': 'Sparks Hall'}, {'bldg': 'URBAN', 'bname': 'Urban Life Bldg'}]