blob: b254ae702e77262652ab5aa37d625f6c57b0f3d7 [file] [log] [blame]
---
name: Install Database Drivers
menu: Installation
index: 2
version: 1
---
Install Database Drivers
-------------
Now that you have Superset up and running on your local machine, along with some example dashboards, lets connect it to a database to run some queries and visualize some data.
Superset runs on Python and requires a database driver to be installed for each type of database. When setting up Superset locally via `docker-compose`, the drivers and packages
contained in [requirements.txt](https://github.com/apache/incubator-superset/blob/master/requirements.txt) and
[requirements-dev.txt](https://github.com/apache/incubator-superset/blob/master/requirements-dev.txt) will
be installed automatically.
At the time of this writing, drivers for the following databases are included:
* [Druid](https://pypi.org/project/pydruid/)
* [Postgres](https://pypi.org/project/psycopg2/)
* [Presto/Hive](https://pypi.org/project/PyHive/)
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.
### 1. Determine the driver you need
To figure out how to install the database driver of your choice, a good starting point is the Datasource Connector section of this documentation for instructions.
Superset interacts with the underlying databases using the provided SQL interface (often times through a SQLAlchemy library). If your database or data engine isn't on the list but a SQL interface exists, please file an issue on the [Superset GitHub repo](https://github.com/apache/incubator-superset/issues), so we can work on supporting it.
[StackOverflow](https://stackoverflow.com/questions/tagged/apache-superset+superset) and the [Superset community Slack](https://join.slack.com/t/apache-superset/shared_invite/enQtNDMxMDY5NjM4MDU0LWJmOTcxYjlhZTRhYmEyYTMzOWYxOWEwMjcwZDZiNWRiNDY2NDUwNzcwMDFhNzE1ZmMxZTZlZWY0ZTQ2MzMyNTU)
are great places to get help with connecting to databases in Superset.
In the end, you should be looking for a Python package compatible with your database. One 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.
In the next few steps, we'll walk through the process of installing a MySQL driver in Superset.
### 2. Install MySQL Driver
As we are currently running inside of a Docker container via `docker compose`, we cannot simply run `pip install mysqlclient` on our local shell and expect the drivers to be installed within the Docker containers for superset.
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. Please follow these steps:
Create `requirements-local.txt`
```
# From the repo root...
touch ./docker/requirements-local.txt
```
Add the driver selected in step above:
```
echo "mysqlclient" >> ./docker/requirements-local.txt
```
Rebuild your local image with the new driver baked in:
```
docker-compose build --force-rm
```
After the rebuild is complete, which make take a few minutes, relaunch:
```
docker-compose up
```
### 3. Connect to MySQL
Now that you've got a MySQL driver installed locally, you should be able to test it out.
We can now create a Datasource in Superset that can be used to connect to a MySQL instance. Assuming your MySQL instance is running locally and can be accessed via localhost, use the following connection string in “SQL Alchemy URI”, by going to Sources > Databases > + icon (to add a new datasource) in Superset.
For Docker running in Linux:
```
mysql://mysqluser:mysqluserpassword@localhost/example?charset=utf8
```
For Docker running in OSX:
```
mysql://mysqluser:mysqluserpassword@docker.for.mac.host.internal/example?charset=utf8
```
Then click “Test Connection”, which should give you an “OK” message. If not, please look at your terminal for error messages, and reach out for help.
Click 'Next' to learn how to make your first chart in Superset.