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()
aW1wb3J0IG15c3FsLmNvbm5lY3RvcgoKbXljb24gPSBteXNxbC5jb25uZWN0b3IuY29ubmVjdCgKICAgICAgICAgICAgaG9zdD0nbG9jYWxob3N0JywgCiAgICAgICAgICAgIHVzZXI9J3Jvb3QnLAogICAgICAgICAgICBwYXNzd29yZD0ncGFzc3dvcmQnLAogICAgICAgICAgICBkYXRhYmFzZT0nU2Nob29sJykKaWYgbXljb24uaXNfY29ubmVjdGVkKCk6CiAgICAgIHByaW50KCdEYXRhYmFzZSBjb25uZWN0ZWQnKQoKY3Vyc29yID0gbXljb24uY3Vyc29yKCkKc3FsPScnJwogICAgICBDUkVBVEUgVEFCTEUgSUYgTk9UIEVYSVNUUyBTVFVERU5UICggCiAgICAgIElEIElOVCBQUklNQVJZIEtFWSwgCiAgICAgIE5hbWUgQ0hBUigxMCksIAogICAgICBTdHJlYW0gQ0hBUigxMCksIAogICAgICBBdmdNYXJrIEZMT0FULAogICAgICBHcmFkZSBDSEFSKDIpLCAKICAgICAgIENsYXNzIENIQVIoNSkpICcnJwoKCmN1cnNvci5leGVjdXRlKHNxbCkKc3FsPScnJwogICAgICAgIElOU0VSVCBJTlRPIFNUVURFTlQgKElELCBOYW1lLCBTdHJlYW0sIEF2Z01hcmssIEdyYWRlLCBDbGFzcykgVkFMVUVTIAogICAgICAgICAgICAgICAgICAgICgxLCAnS2FyYW4nLCAnTWVkaWNhbCcsIDc4LjUsICdCJywgJzEyOCcpLCAKICAgICAgICAgICAgICAgICAgICAoMiwgJ0RpdmFrYXInLCAnQ29tbWVyY2UnLCA4OS4yLCAnQScsICcxMUMnKSwgCiAgICAgICAgICAgICAgICAgICAgKDMsICdEaXZ5YScsICdDb21tZXJjZScsIDY4LjYsICdDJywgJzEyQycpLAogICAgICAgICAgICAgICAgICAgICg0LCAnQXJ1bicsICdDb21wdXRlcnMnLCA4OS45LCAnQScsICcxMkEnKSwKICAgICAgICAgICAgICAgICAgICAoNSwgJ1NhYmluYScsICdNZWRpY2FsJywgODMuMywgJ0InLCAnMTI4JykgJycnCgpjdXJzb3IuZXhlY3V0ZShzcWwpCm15Y29uLmNvbW1pdCgpCmN1cnNvci5leGVjdXRlKCdTRUxFQ1QgKiBGUk9NIFNUVURFTlQnKQpkYXRhID0gY3Vyc29yLmZldGNoYWxsKCkKZm9yICByZWMgaW4gZGF0YTogCiAgICAgIHByaW50KHJlYykKCm15Y29uLmNsb3NlKCkK
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()