0% found this document useful (0 votes)
3 views1 page

MySQL Connector: Python Database Guide

The document shows how to connect to a MySQL database, create a database and table, and insert data into the table using Python code. It connects to the local MySQL server, creates a database called school if it doesn't exist, creates a student table with fields for roll number, class, name, and marks, and inserts a record into the table by taking user input.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

MySQL Connector: Python Database Guide

The document shows how to connect to a MySQL database, create a database and table, and insert data into the table using Python code. It connects to the local MySQL server, creates a database called school if it doesn't exist, creates a student table with fields for roll number, class, name, and marks, and inserts a record into the table by taking user input.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Connection:

import [Link]

mydb=[Link](host="localhost",user="root",passwd="root",database="school")

print(mydb)

Create database:

import [Link]
mydb=[Link](host="localhost",user="root",passwd="root")
mycursor=[Link]()
[Link]("create databaseif not exists school")
[Link]("show databases")
for x in my cursor:
print(x)

Create table:
import [Link]
mydb=[Link](host="localhost",user="root",passwd="root",database="school")
mycursor=[Link]()
[Link]("create table student(rollnoint(3)primary key,clas int,name varchar(20),marks
int(2))")

insert:

import [Link]

mydb=[Link](host="localhost",user="root",passwd="root",database="school")

mycursor=[Link]()

rollno=int(input("Enter rollno"))

clas=int(input("Enter Class"))

name=input("Enter name")

marks=int(input("Enter marks"))

[Link]("insert into student values('"+str(rollno)+"','"+name+"','"+str(clas)+"','"+str(marks)


+"')")

[Link]()

You might also like