WORKING WITH MYSQL DATABASE AND PYTHONsteemCreated with Sketch.

This is a simple program on connecting your python with database and then working with simple SQL query. If you are using Pycharm IDE then you need to first install mysql connector for your python program to work with MySQL database. For this you can go to File->Settings->Project:(you will see your project name)->Python Interpreter. Then click + sign in the top right and search for mysql-connector. Then you can click that and install the package. Then you are good to go.


Screenshot_1.png

I had a database name called userdb in MySQL Workbench and student is the table of that database. I am printing whatever is inside that table. This query will show that.

import mysql.connector

mydb=mysql.connector.connect(host="localhost", user="root", passwd="12345", database="userdb")


mycursor=mydb.cursor()
mycursor.execute("select * from student")

for i in mycursor:
    print(i)

As you run this program, the following output will be seen.


Screenshot_2.png

Coin Marketplace

STEEM 0.16
TRX 0.03
JST 0.026
BTC 13818.37
ETH 407.35
USDT 1.00
SBD 0.99