CRUD Operation in MySQL using Python

Run both command in jupyter to install pymysql and mysqlclient

https://dev.mysql.com/downloads/mysql/

#Installing MySQL on Python :
!pip install pymysql
!pip install mysqlclient

1) Database Connection :

import mysql.connector
# Establishing connection with the SQL  
  
dataBase = mysql.connector.connect( 
  host ="localhost", 
  user ="root", 
  password ="sahil123",
  auth_plugin='mysql_native_password',
  port=3306
) 
# Cursor to the database 
cursor = dataBase.cursor() 
  
cursor.execute("CREATE DATABASE Student") 
print("Student Data base is created") 

Student Data base is created

2) Creating Database Table :

3) INSERT Operation :

1 details inserted

4) INSERT Multiple Operations:

7 details inserted

5) SELECT QUERY:

Displaying NAME and ROLL columns from the STUDENT table:

('Ram', 85)

('Ram', 85)

('Akash', 98)

('Neel', 23)

('Rohan', 43)

('Amit', 87)

('Anil', 45)

('Megha', 55)

('Sita', 95)

6) Update Operation :

Example -2:

7) DELETE OPERATION :

8) DROP TABLE:

Last updated

Was this helpful?