filmov
tv
How To Connect To MySQL In Python (2 Min) | Using Config Parser In Linux

Показать описание
In this tutorial, you'll learn how to connect to MySQL database in Python using MySQL.connector, MySQLConnection, Config Parser & Cursor in Linux.
—
—
Video Transcript:
—
—
Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn how to Connect to the MySQL database in Python. Let's start by looking at the entity relationship diagram.
I have seven tables in my database right now but in this tutorial, we'll mostly be working with the property table. Step one is to create a config file that will contain all the authentication details. Step two is to create a MySQL config reader module that will read this config file and return a dictionary object. Here.
Step three is to create a connect MYSQL module. Here, we are importing the MYSQL connector package and the MYSQL configurator that we just created. In the connect function, we are reading the config file and connecting to the MYSQL database in the try block.
Use the cursor method of the connection object to create a cursor. For the query, I'm selecting the property name and property county from the property table and limiting the output to five rows. Here, I'm printing the property name and county within the for loop while iterating over the cursor.
In the except block, I'm catching errors and displaying them on the console. In the final block, we're closing the connection and at the end calling connect. Let's connect my sequel script to see if it works.
There you have it. Make sure you like, subscribe, and turn on the notification bell. Until next time.
—
—
Video Transcript:
—
—
Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn how to Connect to the MySQL database in Python. Let's start by looking at the entity relationship diagram.
I have seven tables in my database right now but in this tutorial, we'll mostly be working with the property table. Step one is to create a config file that will contain all the authentication details. Step two is to create a MySQL config reader module that will read this config file and return a dictionary object. Here.
Step three is to create a connect MYSQL module. Here, we are importing the MYSQL connector package and the MYSQL configurator that we just created. In the connect function, we are reading the config file and connecting to the MYSQL database in the try block.
Use the cursor method of the connection object to create a cursor. For the query, I'm selecting the property name and property county from the property table and limiting the output to five rows. Here, I'm printing the property name and county within the for loop while iterating over the cursor.
In the except block, I'm catching errors and displaying them on the console. In the final block, we're closing the connection and at the end calling connect. Let's connect my sequel script to see if it works.
There you have it. Make sure you like, subscribe, and turn on the notification bell. Until next time.
Комментарии