# Trouble connecting to MySQL on the same host

**URL:** <https://community.nocodb.com/t/trouble-connecting-to-mysql-on-the-same-host/1372>\
**Category:** Self-Host\
**Created:** [September 14, 2024, 4:49pm UTC](https://community.nocodb.com/t/trouble-connecting-to-mysql-on-the-same-host/1372 "2024-09-14T16:49:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jllerena](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.nocodb.com/jllerena/32/537_2.png) [@Jllerena](https://community.nocodb.com/u/Jllerena)\
**Post date:** [September 14, 2024, 4:49pm UTC](https://community.nocodb.com/t/trouble-connecting-to-mysql-on-the-same-host/1372/1 "2024-09-14T16:49:24Z")

</div>

I installed NocoDB in my local server attached to an instance of MySQL (actually MariaDB) and it runs terrific when I’m connected form my laptop using postman, which means API is working and accessing data.  
But when I try to add a data source (using Connect to External Data), for NocoDB to access another schema on the same MySQL instance, I can’t create a new connection to the database. It keeps telling me “Connection Failure:”. I’m using localhost for the Host address, 3306 for the Port number, and the user name and password I setup directly on MySQL.  
I tested successfully the credentials on the terminal of the server using the command “mysql -h localhost -P 3306 -u -p” and entering the password. So I’m kind of lost. I’m pretty sure the issue is something silly 😜…

---

<div class="post-metadata">

**Author:** ![dstala](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@dstala](https://community.nocodb.com/u/dstala)\
**Post date:** [September 15, 2024, 9:07am UTC](https://community.nocodb.com/t/trouble-connecting-to-mysql-on-the-same-host/1372/2 "2024-09-15T09:07:58Z")

</div>

If you are using localhost external source, you will have to set the following environment variable to true  
“NC\_ALLOW\_LOCAL\_EXTERNAL\_DBS=true”

Connecting to localhost by default is disabled.

---

<div class="post-metadata">

**Author:** ![Jllerena](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.nocodb.com/jllerena/32/537_2.png) [@Jllerena](https://community.nocodb.com/u/Jllerena)\
**Post date:** [September 15, 2024, 10:16pm UTC](https://community.nocodb.com/t/trouble-connecting-to-mysql-on-the-same-host/1372/3 "2024-09-15T22:16:57Z")

</div>

I’m running NocoDB using docker, following the general recommendations. So, should I add the variable just as in “docker run -e NC\_ALLOW\_LOCAL\_EXTERNAL\_DBS=true …” ?  
Is there another way to verify the variable was properly set?  
Cheers,

---

<div class="post-metadata">

**Author:** ![dstala](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@dstala](https://community.nocodb.com/u/dstala)\
**Post date:** [September 16, 2024, 4:56am UTC](https://community.nocodb.com/t/trouble-connecting-to-mysql-on-the-same-host/1372/4 "2024-09-16T04:56:40Z")

</div>

That’s correct. You just have to set it up using `-e` option  
Still facing issue connecting to external source?

---

<div class="post-metadata">

**Author:** ![Jllerena](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.nocodb.com/jllerena/32/537_2.png) [@Jllerena](https://community.nocodb.com/u/Jllerena)\
**Post date:** [September 18, 2024, 1:21am UTC](https://community.nocodb.com/t/trouble-connecting-to-mysql-on-the-same-host/1372/5 "2024-09-18T01:21:54Z")

</div>

Unfortunately, yes…  
The same error (with no description).

---

<div class="post-metadata">

**Author:** ![dstala](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@dstala](https://community.nocodb.com/u/dstala)\
**Post date:** [September 18, 2024, 4:44am UTC](https://community.nocodb.com/t/trouble-connecting-to-mysql-on-the-same-host/1372/6 "2024-09-18T04:44:39Z")

</div>

If you are running mysql also as docker, you will have to use “host.docker.internal” instead of “localhost” as host address. Please confirm if this is the case.

---

<div class="post-metadata">

**Author:** ![Jllerena](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.nocodb.com/jllerena/32/537_2.png) [@Jllerena](https://community.nocodb.com/u/Jllerena)\
**Post date:** [September 18, 2024, 5:51am UTC](https://community.nocodb.com/t/trouble-connecting-to-mysql-on-the-same-host/1372/7 "2024-09-18T05:51:11Z")

</div>

Mmmh… Nope, I’m only running NocoDB in a docker.

---

<div class="post-metadata">

**Author:** ![mertmit](https://avatars.discourse-cdn.com/v4/letter/m/dc4da7/32.png) [@mertmit](https://community.nocodb.com/u/mertmit)\
**Post date:** [September 18, 2024, 6:07am UTC](https://community.nocodb.com/t/trouble-connecting-to-mysql-on-the-same-host/1372/8 "2024-09-18T06:07:58Z")

</div>

Hi @Jllerena  
You still need to use `host.docker.internal` (or if you are using linux `172.17.0.1` as alias will not be added by default in linux).  
Because `localhost` will target container itself but you want to target host of the container.
