Kontext Copilot - An AI-powered assistant for data analytics that runs on your local computer. Learn more
Get started
Create Pandas DataFrame from MySQL
insights Stats
warning Please login first to view stats information.
Raymond
Code Snippets & Tips
Code snippets and tips for various programming languages/frameworks. All code examples are under MIT or Apache 2.0 license unless specified otherwise.
Prerequisites
MySQL connector is required which will be used to establish connection to MySQL database. Refer to the following page for more details about installation.
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', password='hive', host="localhost", port=10101) cursor = conn.cursor() query = "SELECT id, value FROM test_table" df = pd.read_sql(query, con=conn) print(df) conn.close()
copyright
This page is subject to Site terms.
comment Comments
No comments yet.