>>>importMySQLdbaspdb>>>fromconfigimportcredentialsassecrets# assignments >>>db_host=secrets['mysql']['host']>>>db_username=secrets['mysql']['username']>>>db_password=secrets['mysql']['password']>>>db_name=secrets['mysql']['database']# create a connection to the database>>>conn=pdb.connect(host=db_host,user=db_username,passwd=db_password,db=db_name)# create a object for the queries we will be using>>>cursor=conn.cursor()# execute the query>>>cursor.execute('select continent, name from country where continent = "Africa" limit 5')5L# fetch the results by assigning it to the results object:>>>results=cursor.fetchall()# loop and print results:>>>forxinresults:...print(x)...('Africa','Angola')('Africa','Burundi')('Africa','Benin')('Africa','Burkina Faso')('Africa','Botswana')# close the connection>>>conn.close()
Graphing Results to Plotly:
A great blogpost that shows how to use this data to graph the results to plotly