access_time 7 months ago languageEnglish

Create Pandas DataFrame from MySQL

visibility 35 comment 0


MySQL connector is required which will be used to establish connection to MySQL database. Refer to the following page for more details about installation. 

Python: Load Data from MySQL

Code snippet

The following code snippet connects to a database named test_db in server localhost (runs on port 10101) using user name 'hive' and password 'hive'. 

warning Remember to change the connection details to your own ones.  
import mysql.connector
import pandas as pd 

conn = mysql.connector.connect(user='hive', database='test_db',
cursor = conn.cursor()

query = "SELECT id, value FROM test_table"

df = pd.read_sql(query, con=conn)

copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Follow Kontext

Get our latest updates on LinkedIn.

Want to contribute on Kontext to help others?

Learn more

More from Kontext

visibility 45
thumb_up 0
access_time 8 months ago
visibility 346
thumb_up 0
access_time 6 months ago