I have a solution that might work for you. It should give you a nice little pandas.DataFrame.

First, you have to read the query inside the sql file. Then just use the pd.read_sql_query() instead of pd.read_sql()

I am sure you know it, but here is the doc for the function.

# Read the sql file and execute the query
with open('filename.sql', 'r') as query:
    # connection == the connection to your database, in your case prob_db
    DF = pd.read_sql_query(query.read(),connection)

I can assure you that it is working with T-SQL, but I never used it with MySQL.

Answer from Geof on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.read_sql.html
pandas.read_sql — pandas 3.0.1 documentation - PyData |
Returns a DataFrame object that contains the result set of the executed SQL query or an SQL Table based on the provided input, in relation to the specified database connection. ... Read SQL database table into a DataFrame.
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.read_sql.html
pandas.read_sql — pandas 2.2.3 documentation - PyData |
Returns a DataFrame object that contains the result set of the executed SQL query or an SQL Table based on the provided input, in relation to the specified database connection. ... Read SQL database table into a DataFrame.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas read sql query or table with examples
Pandas Read SQL Query or Table with Examples - Spark By {Examples}
December 2, 2024 - Pandas read_sql() function is used to read data from SQL queries or database tables into DataFrame. This function allows you to execute SQL queries and load the results directly into a Pandas DataFrame.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.read_sql_query.html
pandas.read_sql_query — pandas 3.0.1 documentation
pandas.read_sql_query(sql, con, index_col=None, coerce_float=True, params=None, parse_dates=None, chunksize=None, dtype=None, dtype_backend=<no_default>)[source]#
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.read_sql_table.html
pandas.read_sql_table — pandas 3.0.1 documentation
pandas.read_sql_table(table_name, con, schema=None, index_col=None, coerce_float=True, parse_dates=None, columns=None, chunksize=None, dtype_backend=<no_default>)[source]#
🌐
AskPython
askpython.com › home › pandas read_sql: read sql query/database table into a dataframe
Pandas read_sql: Read SQL query/database table into a DataFrame - AskPython
January 31, 2023 - You have learned how to use Pandas to read data from files in a variety of formats, including JSON, CSV, Excel, and others, and how to change data in our previous tutorials. One such way is Pandas read_sql(), which enables you to read a SQL ...
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 72823916 › how-can-i-make-pandas-read-sql
python - How can I make Pandas read SQL? - Stack Overflow
And you need the path to the file, not the URL. import pandas as pd import sqlite3 con = sqlite3.connect('path/Downloads/weather_2012.sqlite') con_memory = sqlite3.connect(":memory:") df = pd.read_sql("SELECT * from weather_2012 LIMIT 3", con) print(df) id date_time temp 1 2012-01-01 00:00:00 -1.8 2 2012-01-01 01:00:00 -1.8 3 2012-01-01 02:00:00 -1.8
🌐
Quora
quora.com › Is-it-possible-to-read-SQL-files-to-load-tables-using-Python-pandas
Is it possible to read .SQL files to load tables using Python pandas? - Quora
Answer (1 of 2): There’s a lot to unpack in this question. First, what do you mean by “.SQL files?” How would you use these “.SQL files” in any way? If they are MySQL backup files (written as text containing MySQL compatible SQL commands) then they’ll be useless when trying to restore ...
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.22.0 › generated › pandas.read_sql.html
pandas.read_sql — pandas 0.22.0 documentation
Other file formats · Performance Considerations · Remote Data Access · Enhancing Performance · Sparse data structures · Frequently Asked Questions (FAQ) rpy2 / R interface · pandas Ecosystem · Comparison with R / R libraries · Comparison with SQL · Comparison with SAS · API Reference · Developer · Internals · Release Notes · Enter search terms or a module, class or function name. pandas.read_sql(sql, con, index_col=None, coerce_float=True, params=None, parse_dates=None, columns=None, chunksize=None)[source]¶ ·
🌐
Stack Abuse
stackabuse.com › reading-and-writing-sql-files-in-pandas
Reading and Writing SQL Files in Pandas
March 15, 2025 - The read_sql() is a Pandas library function that allows us to execute an SQL query and retrieve the results into a Pandas dataframe. The read_sql() function connects SQL and Python, allowing us to take advantage of the power of both languages. The function wraps read_sql_table() and ...
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.pandas › api › pyspark.pandas.read_sql.html
pyspark.pandas.read_sql — PySpark 4.1.1 documentation
pyspark.pandas.read_sql(sql, con, index_col=None, columns=None, **options)[source]# Read SQL query or database table into a DataFrame. This function is a convenience wrapper around read_sql_table and read_sql_query (for backward compatibility). It will delegate to the specific function depending ...
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.14 › generated › pandas.read_sql.html
pandas.read_sql — pandas 0.14.1 documentation
pandas.read_sql(sql, con, index_col=None, coerce_float=True, params=None, parse_dates=None, columns=None)¶
🌐
GeeksforGeeks
geeksforgeeks.org › python › read-sql-database-table-into-a-pandas-dataframe-using-sqlalchemy
Read SQL Database Table into a Pandas DataFrame using SQLAlchemy - GeeksforGeeks
January 15, 2026 - Explanation: pd.read_sql_table("contacts", db) loads all rows from the contacts table into the DataFrame df. Example 2: This program stores student records in a database and reads them into a DataFrame. ... import pandas as pd from sqlalchemy import create_engine, text db = create_engine("sqlite:///students.db") with db.begin() as con: con.execute(text("CREATE TABLE IF NOT EXISTS students (id INTEGER, name TEXT, marks INTEGER)")) con.execute(text("INSERT INTO students VALUES (1,'Oliver',85),(2,'Mia',90)")) df = pd.read_sql_table("students", db) print(df)
🌐
DataLemur
datalemur.com › blog › sql-pandas-read_sql
How to Use Pandas read_sql to Write and Run SQL?
April 21, 2025 - : This function reads an entire SQL table or view into a DataFrame from a database. While Pandas simplifies the extraction of SQL databases within the Python library, it's essential to recognize its limitations.
🌐
TutorialsPoint
tutorialspoint.com › python_pandas › python_pandas_read_sql_method.htm
Python Pandas read_sql() Method
This method is a convenient wrapper ... and simplifies working with databases. Following is the syntax of the Python Pandas read_sql() method −...
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.read_sql.html
pandas.read_sql — pandas 3.0.0rc0+27.g47fea804d6 documentation
Returns a DataFrame object that contains the result set of the executed SQL query or an SQL Table based on the provided input, in relation to the specified database connection. ... Read SQL database table into a DataFrame.