mycon
= mysql.connector
.connect
( host='localhost',
user='root',
password='password',
database='School')
if mycon.is_connected():
print('Database connected')
cursor = mycon.cursor()
sql =''' CREATE TABLE IF NOT EXISTS STUDENT (
ID INT PRIMARY KEY,
Name CHAR(10),
Stream CHAR(10),
AvgMark FLOAT,
Grade CHAR(2),
Class CHAR(5))'''
cursor.execute(sql)
sql = ''' INSERT INTO STUDENT (ID, Name, Stream, AvgMark, Grade, Class)VALUES
(1, 'Karan', 'Medical', 78.5, 'B', '128'),
(2, 'Divakar', 'Commerce', 89.2, 'A', '11C'),
(3, 'Divya', 'Commerce', 68.6, 'C', '12C'),
(4, 'Arun', 'Computers', 89.9, 'A', '12A'),
(5, 'Sabina', 'Medical', 83.3, 'B', '128') '''
cursor.execute(sql)
mycon.commit()
cursor.execute('SELECT * FROM STUDENT')
data = cursor.fetchall()
for rec in data:
print(rec)
mycon.close()
aW1wb3J0IG15c3FsLmNvbm5lY3RvcgpteWNvbiA9IG15c3FsLmNvbm5lY3Rvci5jb25uZWN0KAogICAgaG9zdD0nbG9jYWxob3N0JywKICAgIHVzZXI9J3Jvb3QnLAogICAgcGFzc3dvcmQ9J3Bhc3N3b3JkJywKICAgIGRhdGFiYXNlPSdTY2hvb2wnKQppZiBteWNvbi5pc19jb25uZWN0ZWQoKToKICAgcHJpbnQoJ0RhdGFiYXNlIGNvbm5lY3RlZCcpCmN1cnNvciA9IG15Y29uLmN1cnNvcigpCnNxbCA9JycnIENSRUFURSBUQUJMRSBJRiBOT1QgRVhJU1RTIFNUVURFTlQgKAogICAgSUQgSU5UIFBSSU1BUlkgS0VZLAogICAgTmFtZSBDSEFSKDEwKSwKICAgIFN0cmVhbSBDSEFSKDEwKSwKICAgIEF2Z01hcmsgRkxPQVQsCiAgICBHcmFkZSBDSEFSKDIpLCAKICAgIENsYXNzIENIQVIoNSkpJycnCmN1cnNvci5leGVjdXRlKHNxbCkKc3FsID0gJycnIElOU0VSVCBJTlRPIFNUVURFTlQgKElELCBOYW1lLCBTdHJlYW0sIEF2Z01hcmssIEdyYWRlLCBDbGFzcylWQUxVRVMKICAgICAoMSwgJ0thcmFuJywgJ01lZGljYWwnLCA3OC41LCAnQicsICcxMjgnKSwKICAgICAoMiwgJ0RpdmFrYXInLCAnQ29tbWVyY2UnLCA4OS4yLCAnQScsICcxMUMnKSwKICAgICAoMywgJ0RpdnlhJywgJ0NvbW1lcmNlJywgNjguNiwgJ0MnLCAnMTJDJyksCiAgICAgKDQsICdBcnVuJywgJ0NvbXB1dGVycycsIDg5LjksICdBJywgJzEyQScpLAogICAgICg1LCAnU2FiaW5hJywgJ01lZGljYWwnLCA4My4zLCAnQicsICcxMjgnKSAnJycKY3Vyc29yLmV4ZWN1dGUoc3FsKQpteWNvbi5jb21taXQoKQpjdXJzb3IuZXhlY3V0ZSgnU0VMRUNUICogRlJPTSBTVFVERU5UJykKZGF0YSA9IGN1cnNvci5mZXRjaGFsbCgpCmZvciByZWMgaW4gZGF0YToKICAgcHJpbnQocmVjKQpteWNvbi5jbG9zZSgp
import mysql.connector
mycon = mysql.connector.connect(
host='localhost',
user='root',
password='password',
database='School')
if mycon.is_connected():
print('Database connected')
cursor = mycon.cursor()
sql =''' CREATE TABLE IF NOT EXISTS STUDENT (
ID INT PRIMARY KEY,
Name CHAR(10),
Stream CHAR(10),
AvgMark FLOAT,
Grade CHAR(2),
Class CHAR(5))'''
cursor.execute(sql)
sql = ''' INSERT INTO STUDENT (ID, Name, Stream, AvgMark, Grade, Class)VALUES
(1, 'Karan', 'Medical', 78.5, 'B', '128'),
(2, 'Divakar', 'Commerce', 89.2, 'A', '11C'),
(3, 'Divya', 'Commerce', 68.6, 'C', '12C'),
(4, 'Arun', 'Computers', 89.9, 'A', '12A'),
(5, 'Sabina', 'Medical', 83.3, 'B', '128') '''
cursor.execute(sql)
mycon.commit()
cursor.execute('SELECT * FROM STUDENT')
data = cursor.fetchall()
for rec in data:
print(rec)
mycon.close()