blob: cd7693ad527389ea8ec652423be85199ff56f15a [file] [log] [blame]
"use strict";(self.webpackChunkdocs_v_2=self.webpackChunkdocs_v_2||[]).push([[4281],{62571:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>l,contentTitle:()=>i,default:()=>u,frontMatter:()=>a,metadata:()=>s,toc:()=>c});var n=r(83117),o=(r(67294),r(3905));const a={title:"Adding New Drivers in Docker",hide_title:!0,sidebar_position:2,version:1},i=void 0,s={unversionedId:"databases/docker-add-drivers",id:"databases/docker-add-drivers",title:"Adding New Drivers in Docker",description:"Adding New Database Drivers in Docker",source:"@site/docs/databases/docker-add-drivers.mdx",sourceDirName:"databases",slug:"/databases/docker-add-drivers",permalink:"/docs/databases/docker-add-drivers",draft:!1,editUrl:"https://github.com/apache/superset/tree/master/docs/docs/databases/docker-add-drivers.mdx",tags:[],version:"current",sidebarPosition:2,frontMatter:{title:"Adding New Drivers in Docker",hide_title:!0,sidebar_position:2,version:1},sidebar:"tutorialSidebar",previous:{title:"Installing Database Drivers",permalink:"/docs/databases/installing-database-drivers"},next:{title:"Using Database Connection UI",permalink:"/docs/databases/db-connection-ui"}},l={},c=[{value:"Adding New Database Drivers in Docker",id:"adding-new-database-drivers-in-docker",level:2},{value:"1. Determine the driver you need",id:"1-determine-the-driver-you-need",level:3},{value:"2. Install MySQL Driver",id:"2-install-mysql-driver",level:3},{value:"3. Connect to MySQL",id:"3-connect-to-mysql",level:3}],d={toc:c},p="wrapper";function u(e){let{components:t,...r}=e;return(0,o.kt)(p,(0,n.Z)({},d,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("h2",{id:"adding-new-database-drivers-in-docker"},"Adding New Database Drivers in Docker"),(0,o.kt)("p",null,"Superset requires a Python database driver to be installed for each additional type of database you\nwant to connect to. When setting up Superset locally via ",(0,o.kt)("inlineCode",{parentName:"p"},"docker compose"),", the drivers and packages\ncontained in\n",(0,o.kt)("a",{parentName:"p",href:"https://github.com/apache/superset/blob/master/requirements.txt"},"requirements.txt")," and\n",(0,o.kt)("a",{parentName:"p",href:"https://github.com/apache/superset/blob/master/requirements-dev.txt"},"requirements-dev.txt"),"\nwill be installed automatically."),(0,o.kt)("p",null,"In this section, we'll walk through how to install the MySQL connector library. The connector\nlibrary installation process is the same for all additional libraries and we'll end this section\nwith the recommended connector library for each database."),(0,o.kt)("h3",{id:"1-determine-the-driver-you-need"},"1. Determine the driver you need"),(0,o.kt)("p",null,"To figure out how to install the ",(0,o.kt)("a",{parentName:"p",href:"/docs/databases/installing-database-drivers"},"database driver")," of your choice."),(0,o.kt)("p",null,"In the example, we'll walk through the process of installing a MySQL driver in Superset."),(0,o.kt)("h3",{id:"2-install-mysql-driver"},"2. Install MySQL Driver"),(0,o.kt)("p",null,"As we are currently running inside of a Docker container via ",(0,o.kt)("inlineCode",{parentName:"p"},"docker compose"),", we cannot simply run\n",(0,o.kt)("inlineCode",{parentName:"p"},"pip install mysqlclient")," on our local shell and expect the drivers to be installed within the\nDocker containers for superset."),(0,o.kt)("p",null,"In order to address this, the Superset ",(0,o.kt)("inlineCode",{parentName:"p"},"docker compose")," setup comes with a mechanism for you to\ninstall packages locally, which will be ignored by Git for the purposes of local development. Please\nfollow these steps:"),(0,o.kt)("p",null,"Create ",(0,o.kt)("inlineCode",{parentName:"p"},"requirements-local.txt")),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre"},"# From the repo root...\ntouch ./docker/requirements-local.txt\n")),(0,o.kt)("p",null,"Add the driver selected in step above:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre"},'echo "mysqlclient" >> ./docker/requirements-local.txt\n')),(0,o.kt)("p",null,"Rebuild your local image with the new driver baked in:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre"},"docker compose build --force-rm\n")),(0,o.kt)("p",null,"After the rebuild of the Docker images is complete (which may take a few minutes) you can relaunch using the following command:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre"},"docker compose up\n")),(0,o.kt)("p",null,"The other option is to start Superset via Docker Compose is using the recipe in ",(0,o.kt)("inlineCode",{parentName:"p"},"docker-compose-non-dev.yml"),", which will use pre-built frontend assets and skip the building of front-end assets:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre"},"docker compose -f docker-compose-non-dev.yml pull\ndocker compose -f docker-compose-non-dev.yml up\n")),(0,o.kt)("h3",{id:"3-connect-to-mysql"},"3. Connect to MySQL"),(0,o.kt)("p",null,"Now that you've got a MySQL driver installed locally, you should be able to test it out."),(0,o.kt)("p",null,"We can now create a Datasource in Superset that can be used to connect to a MySQL instance. Assuming\nyour MySQL instance is running locally and can be accessed via localhost, use the following\nconnection string in \u201cSQL Alchemy URI\u201d, by going to Sources > Databases > + icon (to add a new\ndatasource) in Superset."),(0,o.kt)("p",null,"For Docker running in Linux:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre"},"mysql://mysqluser:mysqluserpassword@localhost/example?charset=utf8\n")),(0,o.kt)("p",null,"For Docker running in OSX:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre"},"mysql://mysqluser:mysqluserpassword@docker.for.mac.host.internal/example?charset=utf8\n")),(0,o.kt)("p",null,"Then click \u201cTest Connection\u201d, which should give you an \u201cOK\u201d message. If not, please look at your\nterminal for error messages, and reach out for help."),(0,o.kt)("p",null,"You can repeat this process for every database you want superset to be able to connect to."))}u.isMDXComponent=!0},3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>h});var n=r(67294);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?a(Object(r),!0).forEach((function(t){o(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):a(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function s(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var l=n.createContext({}),c=function(e){var t=n.useContext(l),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},d=function(e){var t=c(e.components);return n.createElement(l.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},m=n.forwardRef((function(e,t){var r=e.components,o=e.mdxType,a=e.originalType,l=e.parentName,d=s(e,["components","mdxType","originalType","parentName"]),p=c(r),m=o,h=p["".concat(l,".").concat(m)]||p[m]||u[m]||a;return r?n.createElement(h,i(i({ref:t},d),{},{components:r})):n.createElement(h,i({ref:t},d))}));function h(e,t){var r=arguments,o=t&&t.mdxType;if("string"==typeof e||o){var a=r.length,i=new Array(a);i[0]=m;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[p]="string"==typeof e?e:o,i[1]=s;for(var c=2;c<a;c++)i[c]=r[c];return n.createElement.apply(null,i)}return n.createElement.apply(null,r)}m.displayName="MDXCreateElement"}}]);