0% found this document useful (0 votes)
41 views6 pages

PROGRAM2

Computer science file

Uploaded by

Ujjwal Kushwaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views6 pages

PROGRAM2

Computer science file

Uploaded by

Ujjwal Kushwaha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAM-1

''Write a program in python to show all databases in my sql'''

import mysql.connector as c

db=c.connect(host='localhost',username='root',passwd='root')

ac=db.cursor()

ac.execute("show databases")

for i in ac:

print(i)

db.close()

o/p

>>>

==== RESTART: C:/Users/USER/AppData/Local/Programs/Python/Python39/conn2.py ====

('abhay1',)

('dbmohit',)

('health',)

('information_schema',)

('mysql',)

('om',)

('om_rastogi',)

('omnss1',)

('performance_schema',)

('priyanshi',)

('py',)

('schoolnss',)

('sys',)

>>>
PROGRAM-2

'''Write a program in python to show tables in mysql'''

import mysql.connector as c

db=c.connect(host='localhost',database='priyanshi' ,username='root', passwd='root')

cm=db.cursor()

cm.execute("show tables")

for i in cm:

print(i)

db.close()

o/p

>>>

==== RESTART: C:/Users/USER/AppData/Local/Programs/Python/Python39/conn1.py ====

('student1',)

('student2',)

('student3',)
PROGRAM-3

'''Write a program in python to show records given tables in mysql'''

import mysql.connector as c

db=c.connect(host='localhost',database='priyanshi',username='root',passwd='root')

ac=db.cursor()

ac.execute("select* from student3")

for i in ac:

print(i)

db.close()

o/p

>>>

==== RESTART: C:/Users/USER/AppData/Local/Programs/Python/Python39/conn3.py ====

(1, 'checks mix', 'pcs', 16)

(6, 'check mix', 'pcfs', 15)

(2, 'heck mix', 'pcf', 14)

>>>
PROGRAM-4

''Write a program in python to insert data given tables in mysql'''

import mysql.connector as c

db=c.connect(host='localhost',database='priyanshi',username='root',passwd='root')

ac=db.cursor()

ac.execute("insert into student3 values(11,'jay','sbd',350)")

db.commit()

db.close()

o/p

>>>

==== RESTART: C:/Users/USER/AppData/Local/Programs/Python/Python39/conn4.py ====

>>>
PROGRAM-5

'''Write a program in python to create a tables in mysql'''

import mysql.connector as c

db=c.connect(host='localhost',database='priyanshi',username='root',passwd='root')

ac=db.cursor()

ac.execute("create table nss1( name varchar(25),address char(21),salery int)")

db.commit()

db.close()

O/P

>>>

================================================ RESTART: C:/Users/USER/AppData/Local/


Programs/Python/Python39/conn5.py ===============================================

>>>
PROGRAM-6

'''Write a program in python to update the item_id given tables in mysql'''

import mysql.connector as c

db=c.connect(host='localhost',database='priyanshi',username='root',passwd='root')

ac=db.cursor()

ac.execute("update student3 set item_id=45 where item_name= 'jay'")

db.commit()

db.close()

O/P

================================================ RESTART: C:/Users/USER/AppData/Local/


Programs/Python/Python39/conn5.py ===============================================

>>>

================================================ RESTART: C:/Users/USER/AppData/Local/


Programs/Python/Python39/conn6.py ===============================================

>>>

You might also like