# Connecting to External mysql DB (2018)

**URL:** <https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [December 17, 2018, 8:34pm UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052 "2018-12-17T20:34:25Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![polignano\_francis](https://avatars.discourse-cdn.com/v4/letter/p/43a26b/32.png) [@polignano\_francis](https://forum.wixstudio.com/u/polignano_francis)\
**Post date:** [December 17, 2018, 8:34pm UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052/1 "2018-12-17T20:34:25Z")

</div>

Hi - I am new to Wix and I’m trying to connect to an external mysql DB. I’ve seen people say that it was not possible in the past but I’ve read of people using NPM mysql. I’m wondering what is the best/easiest way to do this in late 2018.

I tried to get the sample code from here [mysql - npm](https://www.npmjs.com/package/mysql) working on a backend web module but get the error ‘require’ is not defined.

Any advice is appreciated! Thanks

---

<div class="post-metadata">

**Author:** ![giri-zano](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/giri-zano/32/80469_2.png) [@giri-zano](https://forum.wixstudio.com/u/giri-zano)\
**Post date:** [December 17, 2018, 8:45pm UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052/2 "2018-12-17T20:45:34Z")

</div>

this has come up before. Search this forum on “require”. Basically, if I remember correctly, require is flagged as an error in the editor (red dot), but will run in Publish Mode. If you want to avoid this, replace “require” with import. There are enough examples around in the Tics and Tricks section. Good luck.  
And BTW: keep me updated on the progress. Very interested to know how far you get, what you needed to (re)develop (like data binding, if you use Wix Code Input elements).

---

<div class="post-metadata">

**Author:** ![polignano\_francis](https://avatars.discourse-cdn.com/v4/letter/p/43a26b/32.png) [@polignano\_francis](https://forum.wixstudio.com/u/polignano_francis)\
**Post date:** [December 17, 2018, 8:47pm UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052/3 "2018-12-17T20:47:59Z")

</div>

Thanks for the reply! I’ll take a look at older posts. Sounds like I’m on the right track with npm mysql

---

<div class="post-metadata">

**Author:** ![polignano\_francis](https://avatars.discourse-cdn.com/v4/letter/p/43a26b/32.png) [@polignano\_francis](https://forum.wixstudio.com/u/polignano_francis)\
**Post date:** [December 26, 2018, 3:03pm UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052/4 "2018-12-26T15:03:14Z")

</div>

Update: I was able to get the “require” mysql to work and I can successfully connect to my DB. However, when I try to pass data from the DB into the front end from the back end I get “Uncaught (in promise) Error: Bad Gateway”. I’ve mimicked what I want to do locally with Node.js and it works so I’m wondering if it just something with the Wix environment. Do you have any ideas?

---

<div class="post-metadata">

**Author:** ![usaircompressors](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/usaircompressors/32/9577_2.png) [@usaircompressors](https://forum.wixstudio.com/u/usaircompressors)\
**Post date:** [March 1, 2019, 12:27am UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052/5 "2019-03-01T00:27:33Z")

</div>

Have you been able to solve require problem?

---

<div class="post-metadata">

**Author:** ![polignano\_francis](https://avatars.discourse-cdn.com/v4/letter/p/43a26b/32.png) [@polignano\_francis](https://forum.wixstudio.com/u/polignano_francis)\
**Post date:** [March 1, 2019, 12:45pm UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052/6 "2019-03-01T12:45:49Z")

</div>

yes, I was able to figure it out.

---

<div class="post-metadata">

**Author:** ![usaircompressors](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/usaircompressors/32/9577_2.png) [@usaircompressors](https://forum.wixstudio.com/u/usaircompressors)\
**Post date:** [March 2, 2019, 1:27pm UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052/7 "2019-03-02T13:27:45Z")

</div>

can you help me to get connected and write some data to mysql database. A sample code will be very helpful

---

<div class="post-metadata">

**Author:** ![jakesheets22](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jakesheets22/32/9683_2.png) [@jakesheets22](https://forum.wixstudio.com/u/jakesheets22)\
**Post date:** [March 4, 2019, 3:55pm UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052/8 "2019-03-04T15:55:26Z")

</div>

i need this too…any luck??

---

<div class="post-metadata">

**Author:** ![polignano\_francis](https://avatars.discourse-cdn.com/v4/letter/p/43a26b/32.png) [@polignano\_francis](https://forum.wixstudio.com/u/polignano_francis)\
**Post date:** [March 4, 2019, 3:57pm UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052/9 "2019-03-04T15:57:24Z")

</div>

@jakesheets22 yea, check out this thread I posted. I posted the solution that worked for me in it. [https://www.wix.com/code/home/forum/community-discussion/best-way-to-retrieve-data-from-an-external-mysql-db](https://www.wix.com/code/home/forum/community-discussion/best-way-to-retrieve-data-from-an-external-mysql-db)

---

<div class="post-metadata">

**Author:** ![jakesheets22](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jakesheets22/32/9683_2.png) [@jakesheets22](https://forum.wixstudio.com/u/jakesheets22)\
**Post date:** [March 4, 2019, 4:00pm UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052/10 "2019-03-04T16:00:08Z")

</div>

@polignano_francis great help – quick reply … thank you !!!

---

<div class="post-metadata">

**Author:** ![polignano\_francis](https://avatars.discourse-cdn.com/v4/letter/p/43a26b/32.png) [@polignano\_francis](https://forum.wixstudio.com/u/polignano_francis)\
**Post date:** [March 4, 2019, 4:03pm UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052/11 "2019-03-04T16:03:16Z")

</div>

@jakesheets22 no problem! let me know if that works for you …

---

<div class="post-metadata">

**Author:** ![usaircompressors](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/usaircompressors/32/9577_2.png) [@usaircompressors](https://forum.wixstudio.com/u/usaircompressors)\
**Post date:** [March 9, 2019, 8:32pm UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052/12 "2019-03-09T20:32:49Z")

</div>

@jakesheets22 Have you been able to fix your problem?

---

<div class="post-metadata">

**Author:** ![activedata2019](https://avatars.discourse-cdn.com/v4/letter/a/dbc845/32.png) [@activedata2019](https://forum.wixstudio.com/u/activedata2019)\
**Post date:** [February 18, 2020, 1:15pm UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052/13 "2020-02-18T13:15:17Z")

</div>

Hi tpolig01,

I’m starting to use Wix to create a site, and one of the functions we chose it is because it allows to connect with an external MySQL DB. We have one, but weren´t able to connect to it.

We connect to it locally and over Internet, via php, via vb.net and so on, but no way to do it via Wix.

We’ve tried to add the Database as a external collection, but doesn’t work. Have open a ticket with Wix a few days ago, but still haven’t got a response. It seems that adding npm mysql module is the first step, but don’t know wich are the next ones.I’ve read all your posts, and it seems you were in a similar situation, and solved it, but I can’t see how you do it.

So If you could gave me some basic instructions about how to call the BackEnd .jsw module from the Front End to get the MySQL data in my page, I’ll be very gratefull. Thank you anyway for your posted code.

l

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [February 18, 2020, 1:31pm UTC](https://forum.wixstudio.com/t/connecting-to-external-mysql-db-2018/12052/14 "2020-02-18T13:31:22Z")

</div>

Corvid lets you connect your site to an external collection and then work with that collection in your site just as you would with our built in collections. See [Corvid: Working with External Database Collections](https://support.wix.com/en/article/corvid-working-with-external-database-collections) and [Corvid: Adding and Deleting an External Database Collection](https://support.wix.com/en/article/corvid-adding-and-deleting-an-external-database-collection) .

Take a look at the docs and come back here to ask questions and share your experiences.

This is an old thread and will be closed.
