awswrangler.mysql.read_sql_table

awswrangler.mysql.read_sql_table(table: str, con: pymysql.connections.Connection[Any], schema: str | None = None, index_col: str | list[str] | None = None, params: list[Any] | tuple[Any, ...] | dict[Any, Any] | None = None, chunksize: None = None, dtype: dict[str, DataType] | None = None, safe: bool = True, timestamp_as_object: bool = False, dtype_backend: Literal['numpy_nullable', 'pyarrow'] = 'numpy_nullable') DataFrame
awswrangler.mysql.read_sql_table(table: str, con: pymysql.connections.Connection[Any], *, schema: str | None = None, index_col: str | list[str] | None = None, params: list[Any] | tuple[Any, ...] | dict[Any, Any] | None = None, chunksize: int, dtype: dict[str, DataType] | None = None, safe: bool = True, timestamp_as_object: bool = False, dtype_backend: Literal['numpy_nullable', 'pyarrow'] = 'numpy_nullable') Iterator[pd.DataFrame]
awswrangler.mysql.read_sql_table(table: str, con: pymysql.connections.Connection[Any], *, schema: str | None = None, index_col: str | list[str] | None = None, params: list[Any] | tuple[Any, ...] | dict[Any, Any] | None = None, chunksize: int | None, dtype: dict[str, DataType] | None = None, safe: bool = True, timestamp_as_object: bool = False, dtype_backend: Literal['numpy_nullable', 'pyarrow'] = 'numpy_nullable') pd.DataFrame | Iterator[pd.DataFrame]

Return a DataFrame corresponding the table.

Parameters:
  • table (str) – Table name.

  • con (pymysql.connections.Connection) – Use pymysql.connect() to use credentials directly or wr.mysql.connect() to fetch it from the Glue Catalog.

  • schema (str, optional) – Name of SQL schema in database to query. Uses default schema if None.

  • index_col (Union[str, List[str]], optional) – Column(s) to set as index(MultiIndex).

  • params (Union[List, Tuple, Dict], optional) – List of parameters to pass to execute method. The syntax used to pass parameters is database driver dependent. Check your database driver documentation for which of the five syntax styles, described in PEP 249’s paramstyle, is supported.

  • chunksize (int, optional) – If specified, return an iterator where chunksize is the number of rows to include in each chunk.

  • dtype (Dict[str, pyarrow.DataType], optional) – Specifying the datatype for columns. The keys should be the column names and the values should be the PyArrow types.

  • safe (bool) – Check for overflows or other unsafe data type conversions.

  • timestamp_as_object (bool) – Cast non-nanosecond timestamps (np.datetime64) to objects.

  • dtype_backend (str, optional) –

    Which dtype_backend to use, e.g. whether a DataFrame should have NumPy arrays, nullable dtypes are used for all dtypes that have a nullable implementation when “numpy_nullable” is set, pyarrow is used for all dtypes if “pyarrow” is set.

    The dtype_backends are still experimential. The “pyarrow” backend is only supported with Pandas 2.0 or above.

Returns:

Result as Pandas DataFrame(s).

Return type:

Union[pandas.DataFrame, Iterator[pandas.DataFrame]]

Examples

Reading from MySQL using a Glue Catalog Connections

>>> import awswrangler as wr
>>> con = wr.mysql.connect("MY_GLUE_CONNECTION")
>>> df = wr.mysql.read_sql_table(
...     table="my_table",
...     schema="test",
...     con=con
... )
>>> con.close()