# MySQL Connection closes when writing to database from multiple workers

**URL:** <https://discourse.julialang.org/t/mysql-connection-closes-when-writing-to-database-from-multiple-workers/92916>\
**Category:** Data\
**Created:** [January 13, 2023, 11:54am UTC](https://discourse.julialang.org/t/mysql-connection-closes-when-writing-to-database-from-multiple-workers/92916 "2023-01-13T11:54:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SanAlphaTau](https://avatars.discourse-cdn.com/v4/letter/s/e19adc/32.png) [@SanAlphaTau](https://discourse.julialang.org/u/SanAlphaTau)\
**Post date:** [January 13, 2023, 11:54am UTC](https://discourse.julialang.org/t/mysql-connection-closes-when-writing-to-database-from-multiple-workers/92916/1 "2023-01-13T11:54:10Z")

</div>

Heya,

I am trying to write data generated by a compute intensive function into a database for storage and later analysis.

I have been trying to use MySQL.jl to manage the connection. I am running into an issue where when using MySQl.jl with distributed workers the connection closes and I don’t understand the error stack.

I need to use a database as the outputs are quite large, but not attached to MySQL.jl if there is a more up-to-date or better way of doing this.

```julia
using Distributed 
# addprocs(4)

@everywhere begin
    using MySQL
end

println("Opening DB Connection")

@everywhere dbName = "model"
@everywhere connection = DBInterface.connect(MySQL.Connection, "localhost","username", "password", db = dbName)

# on worker 2
@sync @distributed for i in 1:10
    query = string("INSERT INTO dummy (number) VALUES(", myid()+10+i,")")
    DBInterface.execute(connection, query)
end

```

thanks for the help!

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [January 13, 2023, 2:26pm UTC](https://discourse.julialang.org/t/mysql-connection-closes-when-writing-to-database-from-multiple-workers/92916/2 "2023-01-13T14:26:12Z")

</div>

> [@SanAlphaTau](#):
>
> I don’t understand the error stack

It would probably still be very helpful if you posted it 🙂
