oursolutionarchitectoursolutionarchitect

Python MySQL


What is MYSQLdb?

MySQLdb is an interface for connecting to a MySQL database server from Python. It implements the Python Database API v2.0 and is built on top of the MySQL C API.
 

Packages to Install 

mysql-connector-python
mysql-python

If using anaconda 

conda install -c anaconda mysql-python
conda install -c anaconda mysql-connector-python

else 

pip install MySQL-python
pip install MySQL-python-connector

Import-Package 

import MYSQLdb

 How to connect to a remote MySQL database using python?

Before we start you should know the basics of SQL. Now let us discuss the methods used in this code: 

  • connect(): This method is used for creating a connection to our database it has four arguments:
  1. Server Name
  2. Database User Name
  3. Database Password
  4. Database Name
  • cursor(): This method creates a cursor object that is capable of executing SQL queries on the database.
  • execute(): This method is used for executing SQL queries on the database. It takes a sql query( as string) as an argument.
  • fetchone(): This method retrieves the next row of a query result set and returns a single sequence, or None if no more rows are available.
  • close() : This method close the database connection.
     

Free remote mysql database providers: 
1.www.freemysqlhosting.net 
2.www.heliohost.org