0% found this document useful (0 votes)
2 views3 pages

Python MySQL Connectivity Guide

The document provides a guide on connecting Python to a MySQL database using the mysql.connector module. It includes installation resources, example code for establishing a connection, creating a database and table, and executing basic SQL commands. Additionally, it demonstrates how to retrieve data from the database using a cursor object.

Uploaded by

tkulkarni2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Python MySQL Connectivity Guide

The document provides a guide on connecting Python to a MySQL database using the mysql.connector module. It includes installation resources, example code for establishing a connection, creating a database and table, and executing basic SQL commands. Additionally, it demonstrates how to retrieve data from the database using a cursor object.

Uploaded by

tkulkarni2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python-MYSQL Database Connectivity

Installation Resource: [Link]

Program 1: Practical no 25

# Importing module
import [Link]
# Creating connection object
conn = [Link]( host = "localhost", user = "root", password = "Gpp@1234")
# Printing the connection object
if conn.is_connected():
print("Connection Established")
print(conn)

Output:

>>>
===== RESTART: C:/Users/DELL/AppData/Local/Programs/Python/Python38/DB_1.py ====
Connection Established
<[Link].connection_cext.CMySQLConnection object at 0x0000000002D6FD00>
>>>
MYSQL Basic Commands: [Link]

Open MYSQL Command line interface

mysql>show databases;

mysql> create database gppit

mysql> use gppit

mysql> CREATE TABLE Employee( EmpID int, LastName varchar(255), FirstName


varchar(255),City varchar(255));

mysql> select * from employee;


mysql> insert into employee

-> values(1,'ABC','XYZ','Pune');

Program 2: Practical no 26

import [Link]
#establishing the connection
conn = [Link]( user='root', password='Gpp@1234', host='localhost',
database='gppit')
#Creating a cursor object using the cursor() method
mycursor = [Link]()

[Link]("SELECT * FROM employee")

myresult = [Link]()

for x in myresult:
print(x)

Output:
>>>
===== RESTART: C:/Users/DELL/AppData/Local/Programs/Python/Python38/DB_2.py ====
(1, 'ABC', 'XYZ', 'Pune')
>>>

You might also like