Querying the database

At this point, our database is ready for some Python script. Let's create a new Python file and provide database parameters:

import MySQLdbSQL_IP ="10.10.10.130"SQL_USERNAME="root"SQL_PASSWORD="EnterpriseAutomation"SQL_DB="TestingPython"sql_connection = MySQLdb.connect(SQL_IP,SQL_USERNAME,SQL_PASSWORD,SQL_DB)print sql_connection

The parameters provided (SQL_IP, SQL_USERNAME, SQL_PASSWORD, and SQL_DB) are needed to establish the connection and authenticate against the database on port 3306.

The following table mentions the parameters and their meaning:

Parameter Meaning
host The server IP address that has the mysql installation.
user The username with administrative privileges over the connected database.
passwd ...

Get Hands-On Enterprise Automation with Python. now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.