Mysql-Python Connectivity Manual (Prepared by Archana Purwar)
The document provides a 13 step process for connecting MySQL to Python: 1) install MySQLdb package, 2) check for existing package or install, 3) verify installation, 4) open MySQL, 5) check target database, 6) open file to create table via Python script connecting to database, 7) run script, 8) insert single and all column data, 9) update data, 10) select all data, 11) select few columns, 12) delete data, 13) drop table.
Mysql-Python Connectivity Manual (Prepared by Archana Purwar)
The document provides a 13 step process for connecting MySQL to Python: 1) install MySQLdb package, 2) check for existing package or install, 3) verify installation, 4) open MySQL, 5) check target database, 6) open file to create table via Python script connecting to database, 7) run script, 8) insert single and all column data, 9) update data, 10) select all data, 11) select few columns, 12) delete data, 13) drop table.
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 .