diff --git a/ibis/backends/mysql/__init__.py b/ibis/backends/mysql/__init__.py index dd9ef3056d58..467fa9b7155e 100644 --- a/ibis/backends/mysql/__init__.py +++ b/ibis/backends/mysql/__init__.py @@ -66,6 +66,7 @@ def _from_url(self, url: str, **kwargs): "password": url.password or "", "host": url.hostname, "database": database or "", + "port": url.port or None, } for name, value in query_params.items(): @@ -91,6 +92,9 @@ def _from_url(self, url: str, **kwargs): if "password" in kwargs and kwargs["password"] is None: del kwargs["password"] + if "port" in kwargs and kwargs["port"] is None: + del kwargs["port"] + return self.connect(**kwargs) @cached_property diff --git a/ibis/backends/mysql/tests/test_client.py b/ibis/backends/mysql/tests/test_client.py index 1c0d8784adef..f7877f462e46 100644 --- a/ibis/backends/mysql/tests/test_client.py +++ b/ibis/backends/mysql/tests/test_client.py @@ -12,6 +12,13 @@ import ibis import ibis.expr.datatypes as dt from ibis import udf +from ibis.backends.mysql.tests.conftest import ( + IBIS_TEST_MYSQL_DB, + MYSQL_HOST, + MYSQL_PASS, + MYSQL_USER, +) +from ibis.backends.tests.errors import MySQLOperationalError from ibis.util import gen_name MYSQL_TYPES = [ @@ -234,3 +241,10 @@ def test_list_tables_schema_warning_refactor(con): assert mysql_tables.issubset(con.list_tables(database="mysql")) assert mysql_tables.issubset(con.list_tables(database=("mysql",))) + + +def test_invalid_port(): + port = 4000 + url = f"mysql://{MYSQL_USER}:{MYSQL_PASS}@{MYSQL_HOST}:{port}/{IBIS_TEST_MYSQL_DB}" + with pytest.raises(MySQLOperationalError): + ibis.connect(url)