I can't access my MySQL database using the private network.

a year ago

I am using the unit:php8.2 docker image to deploy a Laravel application. I used MYSQLPRIVATEURL variable to connect to the database but I get the error "SQLSTATE[HY000] [2002] phpnetworkgetaddresses: getaddrinfo for mysql.railway.internal failed: nodename nor servname provided, or not known"

0 Replies

a year ago

f89ef06b-231c-4edf-a893-25cbf3c4902b


a year ago

is that an alpine based image?


a year ago

1218658566202855400


a year ago

I think it's based on debian


a year ago

please add a 3 second sleep / delay before you connect to the database


a year ago

I tried it but it still has the same problem, in fact, minutes after the deployment I tried to execute:
railway run sh -c "ping mysql.railway.internal"

but I get:
"ping: cannot resolve mysql.railway.internal: Unknown host"


a year ago

railway run runs the given command locally


a year ago

Oh, i'm adding the sleep in my Dockerfile.


a year ago

please show me how you are implementing the sleep


a year ago

1218661813022097400


a year ago

looks good


a year ago

I don't have the host resolution issue, but apparently there is a restriction for a query in the migration:

SQLSTATE[HY000] [2002] Connection refused (Connection: mysql, SQL: select tablename as name, (datalength + indexlength) as size, tablecommentas comment, engine as engine, tablecollation as collation from informationschema.tables where tableschema = 'forge' and tabletype in ('BASETABLE', 'SYSTEM VERSIONED') order by table_name)


a year ago

is your database in the same project as this app?


a year ago

Yeah.

1218662237062037500


a year ago

railway does not place any such restrictions on the databases besides the amount of resources it can use (cpu / mem /disk based on your plan type)


a year ago

are these logs coming from the build or deploy logs


a year ago

Deply logs


a year ago

Are the env vars availables in build stage?


a year ago

yes but the private network is not


a year ago

It just worked, I moved the "php artisan optimize" command which caches the configuration (includes the DB credentials) and maybe it was pointing to a non-existent database at the execution stage.


a year ago

This is the final configuration.

1218666527461609500


a year ago

awsome


a year ago

How can we mark this as solved?


a year ago

already have


I can't access my MySQL database using the private network. - Railway Help Station