SlideShare a Scribd company logo
Python DB API
Prepared By : Dhara Wagh
Outline
• Definition of Python DB-API
• Python supported databases
• Brief of MySQL
• Prerequisites
• How to connect python with MySQL DB
• Steps to setting up & method to execute MySQL in Python
• Execution of Demo Program
Definition of Python DB-API
• Python Database API (DB-API) is a standardized interface that enables
interactions between Python applications and relational databases.
• It serves as a specification for accessing various database systems in a
uniform manner from Python.
• Python DB-API facilitates essential operations, including connecting to
databases, executing SQL queries, and managing data.
Compatibility with various database
management systems
1. SQLite: A lightweight, self-contained, and serverless database engine.
2.MySQL: A popular open-source relational database management system.
3.PostgreSQL: A powerful, open-source object-relational database system known for its
robust features.
4.Oracle: A widely used enterprise-level relational database management system.
5.Microsoft SQL Server: A comprehensive and feature-rich database system developed
by Microsoft.
6.NoSQL Databases: Certain Python DB-API implementations extend support to
NoSQL databases like MongoDB, enabling interaction with non-tabular data models.
Brief introduction to MySQL
• MySQL is an open-source relational database management system
that is widely used for various applications, ranging from small-
scale to large-scale enterprises. It is known for its speed, reliability,
and ease of use, making it a popular choice for many developers
and organizations.
Prerequisites to work with Python and MySQL
1. Python: Ensure that you have Python installed on your system.
You can download the latest version of Python from the official
website: https://www.python.org/downloads/
2. MySQL Database: You need to have MySQL installed on your
machine or have access to a remote MySQL server. You can
download MySQL from the official website:
https://www.mysql.com/downloads/
Installing the required Python libraries
• To interact with MySQL in Python, you need to install the 'mysql-connector-python' library.
• Use the following command to install it: pip install mysql-connector-python
• Configuring MySQL connection parameters
• You need to specify the host, user, password, and database name to establish a connection
with MySQL.
• For example: Host: "localhost" (if the MySQL server is on the same machine)
User: "yourusername"
Password: "yourpassword"
Database: "yourdatabase"
How to connect python with MySQL DB
• The DB API provides a minimal standard for working with databases using
Python structures and syntax wherever possible. This API includes the
following −
• Importing the API module.
• Acquiring a connection with the database.
• Issuing SQL statements and execute .
• Closing the connection
Setting up MySQL in Python
• Installing and importing the required Python libraries
• Configuring MySQL connection parameters
• Demonstrating how to establish a connection
Importing the Different DB API Module
• # Importing the MySQL DB API module
import mysql.connector
• # Importing the PostgreSQL DB API module
import psycopg2
• # Importing the SQLite DB API module
import sqlite3
Connecting in Python DB-API
• Use the connect() method provided by the specific Python DB-API module to
establish a connection to the desired database.
• Define the necessary connection parameters such as the database's address,
username, password, and other relevant details within the connect() method.
• Upon successful execution, the Python program gains the capability to send and
receive data from the connected database, paving the way for data retrieval,
modification, and more.
Create a connection in Python:
import mysql.connector
mydb = mysql.connector.connect( host="localhost",
user="yourusername“,
password="yourpassword",
database="yourdatabase“ )
**Ensure that the values for host, user, password, and database match the
credentials and details of your MySQL server.
Interacting with the Database
• Create Cursor object and executing SQL queries using Python
• Fetching data from MySQL
• Displaying the results in Python
Creating cursor object
• We need to create the object of a class called cursor that allows Python code to
execute database command in a database session
• After establishing the connection, you can execute SQL queries using the cursor
object.
Mysql / PostgreSql
cursorobj = db.cursor( )
• For example : mycursor = mydb.cursor()
Executing SQL queries using Python
We can execute the sql queries from python program using execute() method
associated with cursor object.
Examples:
mycursor.execute("SELECT * FROM yourtable")
mycursor.execute(“SELECT * from tbl _student”)
mycursor.éxecute("select a from tbl where b=? and c-?”, x, y)
mycursor execute("select a from tbl where b=? and c=?", (х, y))
Execute SOL query
• Executes an SQL. command against all parameter sequences or mappings found in the sequence sq
sql = "INSERT INTO customer (name, address) VALUES (%s, %s)"
val = [
("John Doe", "123 Street, City"),
("Jane Smith", "456 Avenue, Town"),
("Michael Johnson", "789 Road, Village"),
("Sarah Williams", "101 Main Street, Country")
]
mycursor.executemany(sql, val)
Fetch data from MySQL
• MySQL provides multiple ways to retrieve data such as
fetchall() : Fetch all (remaining) rows of a query result, returning them as a
sequence of sequences (eg, a list of tuples).
fetchmany(size) : Fetch the next set of rows of a query result, returning a
sequence of sequences (c.g. a list of tuples) It will return number of rows that
matches to the size argument
fetchone() : Fetch the next row of a query result set, returning a single
sequence, or None when no more data is available
Fetching data from MySQL
• Use the fetchall() method to retrieve the data resulting from the executed
query.
• Assign the fetched data to a variable for further processing.
• For example: result = mycursor.fetchall()
Execute fetch data query
● # Assuming mycursor is the cursor object after executing a query
● mycursor.execute("SELECT * FROM yourtable")
● # Using the fetchall() method to fetch all rows from the result set :
result = mycursor.fetchall()
for row in result:
print(row)
● # Using the fetchone() method to fetch one row at a time from the result set
mycursor.execute("SELECT * FROM yourtable WHERE id = 1")
result = mycursor.fetchone()
print(result)
● # Using the fetchmany() method to fetch a specific number of rows from the result set
mycursor.execute("SELECT * FROM yourtable")
result = mycursor.fetchmany(5)
for row in result:
print(row)
Displaying the results in Python
• Utilize Python's print function to display the fetched data or process it
further according to the requirements.
• For instance:
for x in result:
print(x)
This will print each row retrieved from the MySQL database, based on the
executed query.
Demo Program
import mysql.connector
# Establishing a connection
mydb = mysql.connector.connect( host="localhost",user="root", password="admin“ )
# Creating a cursor object
mycursor = mydb.cursor()
# Creating a database
mycursor.execute("CREATE DATABASE if not exists mydbtest")
print("Database created successfully.")
# Using the created database
mycursor.execute("USE mydbtest")
print("database created successfully.")
Demo Program CONTINUE..
# Creating a table
mycursor.execute("CREATE TABLE if not exists customers (id INT AUTO_INCREMENT
PRIMARY KEY, name VARCHAR(255), address VARCHAR(255))")
# Inserting data into the table
sql = "INSERT INTO customers (name, address) VALUES (%s, %s)"
val = [
("John Doe", "123 Street, City"),
("Jane Smith", "456 Avenue, Town"),
("Michael Johnson", "789 Road, Village"),
("Sarah Williams", "101 Main Street, Country")
]
mycursor.executemany(sql, val)
# Committing the changes
mydb.commit()
print(mycursor.rowcount, "record inserted.")
Demo Program CONTINUE..
#displaying data using select
mycursor.execute("SELECT * FROM customers")
# Fetching the data
result = mycursor.fetchall()
# Displaying the data
for x in result:
print(x)
# Dropping the table
mycursor.execute("DROP TABLE IF EXISTS customers")
print("Table 'customers' deleted successfully.")
# Closing the connection
mydb.close()
print("Connection closed.")
Output :
References
• List of resources for further learning:
1.Python MySQL Database Access - Official Documentation:
https://dev.mysql.com/doc/connector-python/en/
2.W3Schools Python MySQL Tutorial:
https://www.w3schools.com/python/python_mysql_getstarted.asp
3.Real Python - Working with MySQL Databases using Python:
https://realpython.com/python-mysql/
Links to relevant tutorials:
• Python MySQL Connector Documentation:
https://dev.mysql.com/doc/connector-python/en/
• MySQL Documentation: https://dev.mysql.com/doc/
• Python Official Documentation: https://docs.python.org/3/
• MySQL Tutorial on w3schools:
https://www.w3schools.com/python/python_mysql_getstarted.asp
• Real Python's Tutorial on Python MySQL: https://realpython.com/python-mysql/
Any Questions??
Thank You

More Related Content

What's hot (20)

PDF
Functions and modules in python
Karin Lagesen
 
PPTX
Hashing In Data Structure
Meghaj Mallick
 
PPTX
Macro Processor
Saranya1702
 
PPTX
Linked list in Data Structure and Algorithm
KristinaBorooah
 
PPTX
single linked list
Sathasivam Rangasamy
 
PDF
Wrapper classes
Ravi_Kant_Sahu
 
PPTX
Top down parsing
Prankit Mishra
 
PPTX
Linked List
Ashim Lamichhane
 
PPTX
Transaction management DBMS
Megha Patel
 
PPSX
Stacks Implementation and Examples
greatqadirgee4u
 
PPT
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
 
PPTX
linked list
Mohaimin Rahat
 
PPTX
Hashing Technique In Data Structures
SHAKOOR AB
 
PPTX
Polymorphism in c++(ppt)
Sanjit Shaw
 
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
PPTX
This pointer
Kamal Acharya
 
PPT
Addressing modes
Mahesh Kumar Attri
 
PPT
Abstract data types
Poojith Chowdhary
 
PPTX
Presentation on queue
Rojan Pariyar
 
PPTX
INHERITANCE IN JAVA.pptx
NITHISG1
 
Functions and modules in python
Karin Lagesen
 
Hashing In Data Structure
Meghaj Mallick
 
Macro Processor
Saranya1702
 
Linked list in Data Structure and Algorithm
KristinaBorooah
 
single linked list
Sathasivam Rangasamy
 
Wrapper classes
Ravi_Kant_Sahu
 
Top down parsing
Prankit Mishra
 
Linked List
Ashim Lamichhane
 
Transaction management DBMS
Megha Patel
 
Stacks Implementation and Examples
greatqadirgee4u
 
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
 
linked list
Mohaimin Rahat
 
Hashing Technique In Data Structures
SHAKOOR AB
 
Polymorphism in c++(ppt)
Sanjit Shaw
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
This pointer
Kamal Acharya
 
Addressing modes
Mahesh Kumar Attri
 
Abstract data types
Poojith Chowdhary
 
Presentation on queue
Rojan Pariyar
 
INHERITANCE IN JAVA.pptx
NITHISG1
 

Similar to PythonDatabaseAPI -Presentation for Database (20)

PPTX
Interfacing python to mysql (11363255151).pptx
cavicav231
 
PDF
Interface python with sql database.pdf--
jagaspeed09
 
PDF
Interface python with sql database.pdf
MohammadImran709594
 
PPTX
Database Connectivity using Python and MySQL
devsuchaye
 
PPTX
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
PDF
Interface python with sql database10.pdf
HiteshNandi
 
PDF
Python Utilities for Managing MySQL Databases
Mats Kindahl
 
PPTX
3-Chapter-Edit.pptx debre tabour university
alemunuruhak9
 
PPTX
Database connectivity in python
baabtra.com - No. 1 supplier of quality freshers
 
PDF
Python my sql database connection
Learnbay Datascience
 
PPTX
PYTHON MYSQL INTERFACE FOR CLASS XII STUDENTS
sahunamita10
 
PPTX
MySql Interface database in sql python my.pptx
UshimArora
 
PPTX
Python - db.pptx
RAGAVIC2
 
PPTX
PYTHON_DATABASE_CONNECTIVITY.pptxPYTHON_DATABASE
usha raj
 
PPT
PHP - Getting good with MySQL part II
Firdaus Adib
 
PPT
Mysql
guest817344
 
PDF
PHP with MySQL
wahidullah mudaser
 
PDF
9 Python programming notes for ktu physics and computer application semester 4
ebindboby1
 
PDF
Access Data from XPages with the Relational Controls
Teamstudio
 
Interfacing python to mysql (11363255151).pptx
cavicav231
 
Interface python with sql database.pdf--
jagaspeed09
 
Interface python with sql database.pdf
MohammadImran709594
 
Database Connectivity using Python and MySQL
devsuchaye
 
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
Interface python with sql database10.pdf
HiteshNandi
 
Python Utilities for Managing MySQL Databases
Mats Kindahl
 
3-Chapter-Edit.pptx debre tabour university
alemunuruhak9
 
Database connectivity in python
baabtra.com - No. 1 supplier of quality freshers
 
Python my sql database connection
Learnbay Datascience
 
PYTHON MYSQL INTERFACE FOR CLASS XII STUDENTS
sahunamita10
 
MySql Interface database in sql python my.pptx
UshimArora
 
Python - db.pptx
RAGAVIC2
 
PYTHON_DATABASE_CONNECTIVITY.pptxPYTHON_DATABASE
usha raj
 
PHP - Getting good with MySQL part II
Firdaus Adib
 
PHP with MySQL
wahidullah mudaser
 
9 Python programming notes for ktu physics and computer application semester 4
ebindboby1
 
Access Data from XPages with the Relational Controls
Teamstudio
 
Ad

Recently uploaded (20)

PPTX
Introduction to Fluid and Thermal Engineering
Avesahemad Husainy
 
PPTX
quantum computing transition from classical mechanics.pptx
gvlbcy
 
PDF
SG1-ALM-MS-EL-30-0008 (00) MS - Isolators and disconnecting switches.pdf
djiceramil
 
PPTX
Sensor IC System Design Using COMSOL Multiphysics 2025-July.pptx
James D.B. Wang, PhD
 
PPTX
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
PDF
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
PDF
4 Tier Teamcenter Installation part1.pdf
VnyKumar1
 
PPTX
ETP Presentation(1000m3 Small ETP For Power Plant and industry
MD Azharul Islam
 
PPTX
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
PDF
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
PPTX
Online Cab Booking and Management System.pptx
diptipaneri80
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
PDF
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
PPTX
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
PDF
Jual GPS Geodetik CHCNAV i93 IMU-RTK Lanjutan dengan Survei Visual
Budi Minds
 
PDF
IEEE EMBC 2025 「Improving electrolaryngeal speech enhancement via a represent...
NU_I_TODALAB
 
PDF
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
PDF
CFM 56-7B - Engine General Familiarization. PDF
Gianluca Foro
 
PPTX
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
Introduction to Fluid and Thermal Engineering
Avesahemad Husainy
 
quantum computing transition from classical mechanics.pptx
gvlbcy
 
SG1-ALM-MS-EL-30-0008 (00) MS - Isolators and disconnecting switches.pdf
djiceramil
 
Sensor IC System Design Using COMSOL Multiphysics 2025-July.pptx
James D.B. Wang, PhD
 
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
4 Tier Teamcenter Installation part1.pdf
VnyKumar1
 
ETP Presentation(1000m3 Small ETP For Power Plant and industry
MD Azharul Islam
 
sunil mishra pptmmmmmmmmmmmmmmmmmmmmmmmmm
singhamit111
 
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
Online Cab Booking and Management System.pptx
diptipaneri80
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
Jual GPS Geodetik CHCNAV i93 IMU-RTK Lanjutan dengan Survei Visual
Budi Minds
 
IEEE EMBC 2025 「Improving electrolaryngeal speech enhancement via a represent...
NU_I_TODALAB
 
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
CFM 56-7B - Engine General Familiarization. PDF
Gianluca Foro
 
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
Ad

PythonDatabaseAPI -Presentation for Database

  • 1. Python DB API Prepared By : Dhara Wagh
  • 2. Outline • Definition of Python DB-API • Python supported databases • Brief of MySQL • Prerequisites • How to connect python with MySQL DB • Steps to setting up & method to execute MySQL in Python • Execution of Demo Program
  • 3. Definition of Python DB-API • Python Database API (DB-API) is a standardized interface that enables interactions between Python applications and relational databases. • It serves as a specification for accessing various database systems in a uniform manner from Python. • Python DB-API facilitates essential operations, including connecting to databases, executing SQL queries, and managing data.
  • 4. Compatibility with various database management systems 1. SQLite: A lightweight, self-contained, and serverless database engine. 2.MySQL: A popular open-source relational database management system. 3.PostgreSQL: A powerful, open-source object-relational database system known for its robust features. 4.Oracle: A widely used enterprise-level relational database management system. 5.Microsoft SQL Server: A comprehensive and feature-rich database system developed by Microsoft. 6.NoSQL Databases: Certain Python DB-API implementations extend support to NoSQL databases like MongoDB, enabling interaction with non-tabular data models.
  • 5. Brief introduction to MySQL • MySQL is an open-source relational database management system that is widely used for various applications, ranging from small- scale to large-scale enterprises. It is known for its speed, reliability, and ease of use, making it a popular choice for many developers and organizations.
  • 6. Prerequisites to work with Python and MySQL 1. Python: Ensure that you have Python installed on your system. You can download the latest version of Python from the official website: https://www.python.org/downloads/ 2. MySQL Database: You need to have MySQL installed on your machine or have access to a remote MySQL server. You can download MySQL from the official website: https://www.mysql.com/downloads/
  • 7. Installing the required Python libraries • To interact with MySQL in Python, you need to install the 'mysql-connector-python' library. • Use the following command to install it: pip install mysql-connector-python • Configuring MySQL connection parameters • You need to specify the host, user, password, and database name to establish a connection with MySQL. • For example: Host: "localhost" (if the MySQL server is on the same machine) User: "yourusername" Password: "yourpassword" Database: "yourdatabase"
  • 8. How to connect python with MySQL DB
  • 9. • The DB API provides a minimal standard for working with databases using Python structures and syntax wherever possible. This API includes the following − • Importing the API module. • Acquiring a connection with the database. • Issuing SQL statements and execute . • Closing the connection
  • 10. Setting up MySQL in Python • Installing and importing the required Python libraries • Configuring MySQL connection parameters • Demonstrating how to establish a connection
  • 11. Importing the Different DB API Module • # Importing the MySQL DB API module import mysql.connector • # Importing the PostgreSQL DB API module import psycopg2 • # Importing the SQLite DB API module import sqlite3
  • 12. Connecting in Python DB-API • Use the connect() method provided by the specific Python DB-API module to establish a connection to the desired database. • Define the necessary connection parameters such as the database's address, username, password, and other relevant details within the connect() method. • Upon successful execution, the Python program gains the capability to send and receive data from the connected database, paving the way for data retrieval, modification, and more.
  • 13. Create a connection in Python: import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername“, password="yourpassword", database="yourdatabase“ ) **Ensure that the values for host, user, password, and database match the credentials and details of your MySQL server.
  • 14. Interacting with the Database • Create Cursor object and executing SQL queries using Python • Fetching data from MySQL • Displaying the results in Python
  • 15. Creating cursor object • We need to create the object of a class called cursor that allows Python code to execute database command in a database session • After establishing the connection, you can execute SQL queries using the cursor object. Mysql / PostgreSql cursorobj = db.cursor( ) • For example : mycursor = mydb.cursor()
  • 16. Executing SQL queries using Python We can execute the sql queries from python program using execute() method associated with cursor object. Examples: mycursor.execute("SELECT * FROM yourtable") mycursor.execute(“SELECT * from tbl _student”) mycursor.éxecute("select a from tbl where b=? and c-?”, x, y) mycursor execute("select a from tbl where b=? and c=?", (х, y))
  • 17. Execute SOL query • Executes an SQL. command against all parameter sequences or mappings found in the sequence sq sql = "INSERT INTO customer (name, address) VALUES (%s, %s)" val = [ ("John Doe", "123 Street, City"), ("Jane Smith", "456 Avenue, Town"), ("Michael Johnson", "789 Road, Village"), ("Sarah Williams", "101 Main Street, Country") ] mycursor.executemany(sql, val)
  • 18. Fetch data from MySQL • MySQL provides multiple ways to retrieve data such as fetchall() : Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (eg, a list of tuples). fetchmany(size) : Fetch the next set of rows of a query result, returning a sequence of sequences (c.g. a list of tuples) It will return number of rows that matches to the size argument fetchone() : Fetch the next row of a query result set, returning a single sequence, or None when no more data is available
  • 19. Fetching data from MySQL • Use the fetchall() method to retrieve the data resulting from the executed query. • Assign the fetched data to a variable for further processing. • For example: result = mycursor.fetchall()
  • 20. Execute fetch data query ● # Assuming mycursor is the cursor object after executing a query ● mycursor.execute("SELECT * FROM yourtable") ● # Using the fetchall() method to fetch all rows from the result set : result = mycursor.fetchall() for row in result: print(row) ● # Using the fetchone() method to fetch one row at a time from the result set mycursor.execute("SELECT * FROM yourtable WHERE id = 1") result = mycursor.fetchone() print(result) ● # Using the fetchmany() method to fetch a specific number of rows from the result set mycursor.execute("SELECT * FROM yourtable") result = mycursor.fetchmany(5) for row in result: print(row)
  • 21. Displaying the results in Python • Utilize Python's print function to display the fetched data or process it further according to the requirements. • For instance: for x in result: print(x) This will print each row retrieved from the MySQL database, based on the executed query.
  • 22. Demo Program import mysql.connector # Establishing a connection mydb = mysql.connector.connect( host="localhost",user="root", password="admin“ ) # Creating a cursor object mycursor = mydb.cursor() # Creating a database mycursor.execute("CREATE DATABASE if not exists mydbtest") print("Database created successfully.") # Using the created database mycursor.execute("USE mydbtest") print("database created successfully.")
  • 23. Demo Program CONTINUE.. # Creating a table mycursor.execute("CREATE TABLE if not exists customers (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), address VARCHAR(255))") # Inserting data into the table sql = "INSERT INTO customers (name, address) VALUES (%s, %s)" val = [ ("John Doe", "123 Street, City"), ("Jane Smith", "456 Avenue, Town"), ("Michael Johnson", "789 Road, Village"), ("Sarah Williams", "101 Main Street, Country") ] mycursor.executemany(sql, val) # Committing the changes mydb.commit() print(mycursor.rowcount, "record inserted.")
  • 24. Demo Program CONTINUE.. #displaying data using select mycursor.execute("SELECT * FROM customers") # Fetching the data result = mycursor.fetchall() # Displaying the data for x in result: print(x) # Dropping the table mycursor.execute("DROP TABLE IF EXISTS customers") print("Table 'customers' deleted successfully.") # Closing the connection mydb.close() print("Connection closed.")
  • 26. References • List of resources for further learning: 1.Python MySQL Database Access - Official Documentation: https://dev.mysql.com/doc/connector-python/en/ 2.W3Schools Python MySQL Tutorial: https://www.w3schools.com/python/python_mysql_getstarted.asp 3.Real Python - Working with MySQL Databases using Python: https://realpython.com/python-mysql/
  • 27. Links to relevant tutorials: • Python MySQL Connector Documentation: https://dev.mysql.com/doc/connector-python/en/ • MySQL Documentation: https://dev.mysql.com/doc/ • Python Official Documentation: https://docs.python.org/3/ • MySQL Tutorial on w3schools: https://www.w3schools.com/python/python_mysql_getstarted.asp • Real Python's Tutorial on Python MySQL: https://realpython.com/python-mysql/