1import mysql.connector
2import pandas as pd
3
4db_connection = mysql.connector.connect(
5 host="localhost",
6 user="user",
7 password="password",
8 database="dbname",
9 auth_plugin='mysql_native_password'
10)
11
12df = pd.read_sql("select * from table_name;", con=db_connection)
13print(df)
14
1from sqlalchemy import create_engine
2import pymysql
3
4db_connection_str = 'mysql+pymysql://mysql_user:mysql_password@mysql_host/mysql_db'
5db_connection = create_engine(db_connection_str)
6
7df = pd.read_sql('SELECT * FROM table_name', con=db_connection)
8
9# This works with "mysql.connector" as well