0% found this document useful (0 votes)
171 views

Python SQL PDF

The document provides instructions for connecting Python to a MySQL database. It outlines 13 steps: 1) install MySQLdb, 2) check for existing installation and install if needed, 3) verify installation, 4) open MySQL, 5) check target database, 6) open a file to create a table via Python script, 7) run the file, 8) insert data into the table in various ways, 9) perform an update operation, 10-12) perform select operations to retrieve different types of data, and 13) drop the table. The goal is to connect a Python script to a MySQL database and perform basic CRUD operations on a table.

Uploaded by

Aditya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
171 views

Python SQL PDF

The document provides instructions for connecting Python to a MySQL database. It outlines 13 steps: 1) install MySQLdb, 2) check for existing installation and install if needed, 3) verify installation, 4) open MySQL, 5) check target database, 6) open a file to create a table via Python script, 7) run the file, 8) insert data into the table in various ways, 9) perform an update operation, 10-12) perform select operations to retrieve different types of data, and 13) drop the table. The goal is to connect a Python script to a MySQL database and perform basic CRUD operations on a table.

Uploaded by

Aditya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

MySQL-Python connectivity Manual

( Prepared by Archana Purwar)

Step 1: Install the package MySQLdb for coonectivity . To check whether it is already exists ,
do following:
Step 2 : If not, install it :
Step 3: Check if it is installed or not.
Step 4: Open MySQL .

Step 5: Check the database to which you want to connect to.


Step 6: Open a new file to create a table through python script.

# Open database connection // to find user name type at mysql> select user();

# to find host name type at cmd> hostname

db = MySQLdb.connect(hostname, MYSQL username, MYSQL Password, databasename )


Step 7: Run the file.

Check the database. You will find there.


Step 8: (i) Insert the data ( one column) in the table.
(ii) Insert the data( all columns) in the table.
Step 9. Update operation :
Step 10.. Select operation: Retrieve the data .
Step 11.. Select operation: Retrieve few columns .
Step 12.. Delete operation .
Step 13.. Drop Table; .

You might also like