# Custom code mysql too many connections

**URL:** <https://community.hubspot.com/t/custom-code-mysql-too-many-connections/57266>\
**Category:** Data Hub\
**Created:** [May 19, 2022, 6:21am UTC](https://community.hubspot.com/t/custom-code-mysql-too-many-connections/57266 "2022-05-19T06:21:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomasvbe](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/thomasvbe/32/9256_2.png) [@thomasvbe](https://community.hubspot.com/u/thomasvbe)\
**Post date:** [May 19, 2022, 6:21am UTC](https://community.hubspot.com/t/custom-code-mysql-too-many-connections/57266/1 "2022-05-19T06:21:07Z")

</div>

Hi, I’ve got a custom code workflow where I try to get data from an external MySQL database. I get a “too many connections” error because it’s possible that more than 200 contacts go through that workflow at the same time. It needs to fetch data right before an e-mail has to leave. Do you guys have any solution to pass each contact one at a time through a workflow or a custom code step? Or how I can anticipate that there are too many connections? Thanks!

---

<div class="post-metadata">

**Author:** ![jackcoldrick](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jackcoldrick/32/5119_2.png) [@jackcoldrick](https://community.hubspot.com/u/jackcoldrick)\
**Post date:** [May 19, 2022, 11:37am UTC](https://community.hubspot.com/t/custom-code-mysql-too-many-connections/57266/2 "2022-05-19T11:37:48Z")

</div>

Hey @thomasvbe,

There isn’t an ideal solution here as there is no way of throttling how many contacts (or any record for that matter) can enroll into a workflow at any given time. With that said some ideas that spring to mind include:

- Increasing the max\_connections system variable but be mindful that this could impact overall performance depending on volume. More information on how to do that can be found [here](https://ubiq.co/database-blog/how-to-increase-max-connections-in-mysq).
- Another option might be to ensure that you’re closing/terminating the connection within the custom coded action as early as is reasonably possible.

The way our tool is structured is that each contact enrolled that the custom coded workflow action runs against will count towards the total number of client connections you can have at any given time to your database.

I appreciate this isn’t a perfect solution but just wanted to provide some insight on my end.

Jack

---

<div class="post-metadata">

**Author:** ![thomasvbe](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/thomasvbe/32/9256_2.png) [@thomasvbe](https://community.hubspot.com/u/thomasvbe)\
**Post date:** [May 20, 2022, 5:27am UTC](https://community.hubspot.com/t/custom-code-mysql-too-many-connections/57266/3 "2022-05-20T05:27:55Z")

</div>

Hi Jack

We did actually increase the max connections, although this isn’t a future-proof solution.

Thanks!

Thomas
