Getting Started - Installing Additional Drivers
If you haven't already done so, please check out the first post in our "Getting Started" series Installing Apache Superset to install Superset locally.
Now that you have Superset up and running on your machine, along with some example dashboards, you'd probably like to point it at your own database in order to run some queries and visualize.
Superset runs on Python and requires a database driver to be installed for each flavor of DB that you'd like for it to talk to. When setting up Superset locally via
docker-compose, the drivers and packages contained in requirements.txt and requirements-dev.txt will be installed automatically. As of the time of this writing, drivers for the following databases are included:
If your database is one of these, you should be good to go! However, if you want to connect to something different, like MySQL, you would need to install an additional driver.
Installing drivers for local development
1. Determine the driver you need
This part can be a little tricky as it can require a bit of research. Typically, a good starting point is the Superset docs. If your DB isn't in this list, try searching Superset Issues for guidance by others in the community who might have set up your database type. Finally, the Superset community Slack channel is a great resource for asking general questions. In the end, you should be looking for a Python PIP package compatible with your database. The other part that makes database driver installation tricky is the fact that local binaries are sometimes required in order for them to bind properly, which means that various APT packages might need to be installed before Pip can get things set up.
For the purposes of this blog post, we will describe the process of setting up MySQL, which is relatively straight forward. According to the Superset docs (referenced above), we will need to run
pip install mysqlclient in order to get MySQL up and running.
2. Install driver locally
As we are currently running inside of a Docker container via
Docker Compose, we cannot simply run
pip install xxx on our local CMD line and expect drivers to be installed for the containers to use. In order to address this, the Superset
Docker Compose setup comes with a mechanism for you to install packages locally which will be ignored by Git for the purposes of local development.
# From the repo root... touch ./docker/requirements-local.txt
Add the driver selected in step 1 above
echo "mysqlclient" >> ./docker/requirements-local.txt
Rebuild your local image with the new driver baked in
docker-compose build --force-rm
Fire things back up
Now that you've got a new driver installed locally, you should be able to test it out. Carrying our MySQL example forward, we can now create a Datasource that can be used to connect to a MySQL instance. Assuming the instance is running locally and can be accessed via localhost, the following connection string should work:
For Docker running in Linux:
For Docker running in OSX:
Note: As drivers typically have DB connection string options that are specific to their options, it's not possible to list them all here. Therefore, you should read up on your specific driver's options in order to choose those that work best for you.
If you'd like a more production-ready setup for Superset, we are buildling that hosted cloud solution at Preset. The solution is currently in beta, and you can sign up to try it out here. It's a great opportunity for you to help shape this offering, influence our ambitious Superset roadmap, and access Preset’s expertise as an extension of your team.