Python with mysql codes

Fundamentals to mysql to work with python

=======================================================

1. Login to database by importing connector and using connect statement 

from mysql import connector as con

mydb = con.connect(host ='localhost', user='root', password='admin') 

2.create a cursor to move through mydb

cur = mydb.cursor() 

3.execute command with execute() function

cur.execute() #commands in parantheses 

4.display results with functions as fectchall()

results = cur.fetchall() 

5.loop in through results

for data in results:

    print(data)

==========================================================

In Further sections we will go through some examples and know how the things work with sql

==========================================================

1. Making a connection to sql server:-

from mysql import connector as con

mydb = con.connect(host = 'localhost', user = 'root', password = 'admin')

2. Creating a cursor:-

from mysql import connector as con

mydb = con.connect(host = 'localhost', user = 'root', password = 'admin')

cur = mydb.cursor()

Contd..

Comments

Popular posts from this blog

Rough ideas