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
1Importing data from a MySQL database into a Pandas data frame including column names:-
2import mysql.connector as sql.
3import pandas as pd.
4db_connection = sql.connect(host='hostname', database='db_name', user='username', password='password')
5db_cursor = db_connection.cursor()
6db_cursor.execute('SELECT * FROM table_name')