1
votes

I was trying to connect superset with mysql database with this SQLAlchemy URI:mysql://localhost:3306/mysql/database/table1 but not able to connect.

I was getting this error:

ERROR: {"error": "Connection failed!

The error message returned was:
No module named 'MySQLdb'", "stacktrace": "Traceback (most recent call last):
  File \"/Users/akay/venv/lib/python3.7/site-packages/superset/views/core.py\", line 1703, in testconn
    engine = database.get_sqla_engine(user_name=username)
  File \"/Users/akay/venv/lib/python3.7/site-packages/superset/utils/core.py\", line 131, in __call__
    value = self.func(*args, **kwargs)
  File \"/Users/akay/venv/lib/python3.7/site-packages/superset/models/core.py\", line 923, in get_sqla_engine
    return create_engine(url, **params)
  File \"/Users/akay/venv/lib/python3.7/site-packages/sqlalchemy/engine/__init__.py\", line 479, in create_engine
    return strategy.create(*args, **kwargs)
  File \"/Users/akay/venv/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py\", line 87, in create
    dbapi = dialect_cls.dbapi(**dbapi_args)
  File \"/Users/arkay/venv/lib/python3.7/site-packages/sqlalchemy/dialects/mysql/mysqldb.py\", line 118, in dbapi
    return __import__(\"MySQLdb\")
    ModuleNotFoundError: No module named 'MySQLdb'
"}
4
Is there any right way to connect to mysql database ?Instinct

4 Answers

5
votes

MySQLdb is not compatible with Python 3, You need to use pymysql.

Install pymysql:

$ pip install pymysql

Connect to mysql data source with below URI string.

mysql+pymysql://user:pass@host/databasename
0
votes

Configure your database user with hostname=localhost

0
votes

You need to install mysql-connector-python module:

$ pip install mysql-connector-python
0
votes

Had similiar issue. I'm sure this will save time for some of you out there:

Use 127.0.0.1 instead of localhost.

Here is the perfect template for MySQL string:

SQLALCHEMY_DATABASE_URI = 'mysql://username:[email protected]:3306/schema-name'

Install MySQL:

pip3 install mysqlclient 

Upgrade SQLAlchemy:

pip install sqlalchemy==1.3.24

Load DB:

superset db upgrade

Create Admin user:

superset fab create-admin