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

I am using the unit:php8.2 docker image to deploy a Laravel application. I used MYSQL_PRIVATE_URL variable to connect to the database but I get the error "SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql.railway.internal failed: nodename nor servname provided, or not known"
23 Replies
Percy
Percy8mo ago
Project ID: f89ef06b-231c-4edf-a893-25cbf3c4902b
gregorip02
gregorip028mo ago
f89ef06b-231c-4edf-a893-25cbf3c4902b
Brody
Brody8mo ago
is that an alpine based image?
gregorip02
gregorip028mo ago
No description
gregorip02
gregorip028mo ago
I think it's based on debian
Brody
Brody8mo ago
please add a 3 second sleep / delay before you connect to the database
gregorip02
gregorip028mo 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"
Brody
Brody8mo ago
railway run runs the given command locally
gregorip02
gregorip028mo ago
Oh, i'm adding the sleep in my Dockerfile.
Brody
Brody8mo ago
please show me how you are implementing the sleep
gregorip02
gregorip028mo ago
No description
Brody
Brody8mo ago
looks good
gregorip02
gregorip028mo 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 table_name as name, (data_length + index_length) as size, table_commentas comment, engine as engine, table_collation as collation from information_schema.tables where table_schema = 'forge' and table_type in ('BASETABLE', 'SYSTEM VERSIONED') order by table_name)
Brody
Brody8mo ago
is your database in the same project as this app?
gregorip02
gregorip028mo ago
Yeah.
No description
Brody
Brody8mo 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) are these logs coming from the build or deploy logs
gregorip02
gregorip028mo ago
Deply logs Are the env vars availables in build stage?
Brody
Brody8mo ago
yes but the private network is not
gregorip02
gregorip028mo 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.
gregorip02
gregorip028mo ago
This is the final configuration.
No description
Brody
Brody8mo ago
awsome
gregorip02
gregorip028mo ago
How can we mark this as solved?
Brody
Brody8mo ago
already have
Want results from more Discord servers?
Add your server