Issue Summary

I have set up Redash on an Ubuntu server via getredash/setup with no issues whatsoever. When I now try to add my PlanetScale hosted database as a data source, however, I get back the following error:

(2013, "Lost connection to MySQL server at 'reading authorization packet', system error: 11")

This error is both being returned on the connection test that is part of the “New Data Source” page and for when I try to run an actual query from the “New Query” page.

Worth mentioning is that the error gets returned nearly instantly. After browsing Redash’s code it appears you have the connection timeout set to 60s so network related errors or latency can most likely be ruled out.

The logs have this stack trace:

scheduler_1         | [2023-02-27 13:38:01,319][PID:42][WARNING][ForkPoolWorker-26] task_name=redash.tasks.refresh_schema task_id=b4627530-d271-4539-80fc-b2e7eb492f51 Failed refreshing schema for the data source: PlanetScale
scheduler_1         | Traceback (most recent call last):
scheduler_1         |   File "/app/redash/tasks/queries.py", line 261, in refresh_schema
scheduler_1         |     ds.get_schema(refresh=True)
scheduler_1         |   File "/app/redash/models/__init__.py", line 155, in get_schema
scheduler_1         |     schema = sorted(query_runner.get_schema(get_stats=refresh), key=lambda t: t['name'])
scheduler_1         |   File "/app/redash/query_runner/__init__.py", line 142, in get_schema
scheduler_1         |     self._get_tables(schema_dict)
scheduler_1         |   File "/app/redash/query_runner/mysql.py", line 137, in _get_tables
scheduler_1         |     results, error = self.run_query(query, None)
scheduler_1         |   File "/app/redash/query_runner/mysql.py", line 164, in run_query
scheduler_1         |     connection = self._connection()
scheduler_1         |   File "/app/redash/query_runner/mysql.py", line 124, in _connection
scheduler_1         |     connection = MySQLdb.connect(**params)
scheduler_1         |   File "/usr/local/lib/python2.7/site-packages/MySQLdb/__init__.py", line 84, in Connect
scheduler_1         |     return Connection(*args, **kwargs)
scheduler_1         |   File "/usr/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 166, in __init__
scheduler_1         |     super(Connection, self).__init__(*args, **kwargs2)
scheduler_1         | OperationalError: (2013, "Lost connection to MySQL server at 'reading authorization packet', system error: 11")
scheduler_1         | [2023-02-27 13:38:01,320][PID:42][INFO][ForkPoolWorker-26] task_name=redash.tasks.refresh_schema task_id=b4627530-d271-4539-80fc-b2e7eb492f51 task=refresh_schema state=failed ds_id=2 runtime=0.47

PlanetScale is using Vitess, a database clustering system for horizontal sharding of MySQL. There are some compatibility gaps between Vitess and MySQL, but I don’t think any of them are a factor here. They have a connection example for Python’s MySQLdb so it does not seem to be a broader incompatibility either.

PlanetScale also has a CLI utility available that can act as a proxy. If I start that proxy and point my redash installation to it, I can connect and issue queries to my PlanetScale database from within Redash without any issues.

Whether I use the MySQL or MySQL (Amazon RDS) data source does not make any difference.

This leads me to believe that this may be a firewall issue as it’s been discussed earlier in Redash AWS MySQL Connection. My server’s iptables rules are as follows and look good to me, though.

fooforge@prometheus:~/dev/github/setup/data$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy DROP)
target     prot opt source               destination
DOCKER-USER  all  --  anywhere             anywhere
DOCKER-ISOLATION-STAGE-1  all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain DOCKER (3 references)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             172.18.0.7           tcp dpt:5000
ACCEPT     tcp  --  anywhere             172.18.0.8           tcp dpt:http

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target     prot opt source               destination
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere
RETURN     all  --  anywhere             anywhere

Chain DOCKER-ISOLATION-STAGE-2 (3 references)
target     prot opt source               destination
DROP       all  --  anywhere             anywhere
DROP       all  --  anywhere             anywhere
DROP       all  --  anywhere             anywhere
RETURN     all  --  anywhere             anywhere

Chain DOCKER-USER (1 references)
target     prot opt source               destination
RETURN     all  --  anywhere             anywhere

Long story short, I’m out of ideas. If anyone has any pointers for me, I would appreciate it. And, if not, thanks for reading!

Disclaimer: I’m a senior support engineer at PlanetScale. This issue was reported by one of our users. I was able to reproduce it so I’m hoping to get this resolved for them. :upside_down_face:

Technical details:

  • Redash Version: 8.0.0+b32245(a16f551e)
  • Browser/OS: n/a
  • How did you install Redash: getredash/setup on a Ubuntu 22.04 server