Page 92 - PYTHON-12
P. 92
Program 20: Perform all the operations with reference to table ‘Employee’ through
MySQL-Python connectivity.
Solution:
import MySQLdb
# Using connect method to connect database
db1 = MySQLdb.connect("localhost","root","","TESTDB" )
# using cursor() method for preparing cursor
cursor = db1.cursor()
# Preparing SQL statement to create EMP table
sql = "CREATE TABLE EMP(empno integer primary key,ename varchar(25) not null,salary
float);"
cursor.execute(sql)
# disconnect from server
db1.close()