R
Railway

✋|help

failed opening connection to sql: default addr for network

Jjd01829/14/2023
Hi, I am trying to deploy my golang web service which connects to mysql. I have added the mysql url reference variable in my web service but currently see this error in my web service logs:

failed opening connection to sql: default addr for network
Jjd01829/14/2023
project id - 5b1457c9-94bf-4b38-9366-6949b7e8aa19
Bbrody1929/14/2023
can I see a screenshot of your service variables please?
Jjd01829/14/2023
Sure only the one variable at the moment
Bbrody1929/14/2023
looks good to me
show me the code that connects to the database please
Jjd01829/14/2023
Bbrody1929/14/2023
still looks good
do you happen to be using the private network?
Jjd01829/14/2023
Not that I am aware of . New to railway to be honest.

Just created to new services, one the web app and another the mysql service.
Bbrody1929/14/2023
then that's basically a no
go into the service settings and disable private networking
Jjd01829/14/2023
Thanks done that and redeployed but still no joy. Same error in logs.
Bbrody1929/14/2023
hmmm
link me the library you are using for SQL and I'll see if I can whip something up
Jjd01829/14/2023
Appreciate your help.

https://entgo.io/docs/sql-integration/#use-pgx-with-postgresql

Using second option currently under configure sql.DB
Bbrody1929/14/2023
I think I know the problem, so I will get back to you with a definitive answer soon
Jjd01829/14/2023
Amazing. Thanks again.
Bbrody1929/14/2023
alright, so sql.Open wants a connection string in DSN format, you are providing a URL format and URL and DSN formats are not interchangeable, unfortunately railway doesn’t offer a DSN connection string variable so we have to construct our own.
set this service variable in the raw editor
MYSQL_DSN=${{MySQL.MYSQLUSER}}:${{MySQL.MYSQLPASSWORD}}@tcp(${{MySQL.MYSQLHOST}}:${{MySQL.MYSQLPORT}})/${{MySQL.MYSQLDATABASE}}

and heres some example code
mysqlDSN := os.Getenv("MYSQL_DSN")

db, err := sql.Open("mysql", mysqlDSN)
// ...

you of cource can still append your query parameters to mysqlDSN like you where originally doing
Jjd01829/14/2023
Ahh good spot. I will give that a go now!
Brilliant worked a treat.
Bbrody1929/14/2023
awsome
Jjd01829/14/2023
Thank you.
Bbrody1929/14/2023
no problem!

Looking for more? Join the community!

Recommended Posts
Deploying Meilisearch template does not workI have a running project, If I click on new -> template -> Meili then a new service is created. HoweDeploy Flutter, error on buildHelp me! How do I deploy my flutter app on railway?Strapi crashes out of nowhereHello, my Strapi app sometimes crashes out of nowhere. This is not very good, because I have a prod Automatic Scaling not workingProject Id: 70ab406f-186f-40f7-ac61-c1a8dcb4bbb9 I am a user on the Hobby plan, the scaling on my pCron Job Run NowHello, I created a separate service with a cron expression configured. All works well until I try tNo sure that the changes are being applied when railway up.I have a Django app that was working fine until recently. One day, after running `railway up`, I staReferenceError: FormData is not defined in ProductionHello, my codes are working fine on localhost, but when I push the codes to railway it throws this mNestJS app starts correctly but receives SIGTERM after 20 seconds (Hobby Plan)Hello ! I've managed to successfully deployed and start my NestJS app, but I receive a SIGTERM 20 sFlask App Keep Getting Called From 192.168.0.xI'm not sure if this is the right place to ask, but i noticed that my app is getting call from 192.1sslIm new to all this so bare with me. I have a .dev site and the ssl giving me some issues. I'm gettiDeploy Logs Incorrectly Highlighting Logs as ErrorI'm having this issue with a custom log formatter on python defined like this: ``` formatter = loggDeployment stuck while pushing the image and failing after ~30minsHi, I have 4 environment in a project. I'm deploying fastapi application using uvicorn, it was takinpg_restoreIs remote postgres pg_restore from a local binary dump file supposed to take super long? It took likRemove 2FAHi!  I had a string of bad luck and lost my 2FA key for my account. Then I proceeded to use my recoRegion SelectionThe database and the services I work with are in the European region so I'm experiencing some delaysExperiencing crash with no output for the reason of the crash.Hello, I'm having issues with my project that I'm working on. I'm trying to test uploading some datRailway StrapiHi. It's taken me entire day and I think I am getting close. I deployed Strapi with postgres on RailLogs down?I haven't been able to see any logs, deploy or build or observability for the past 15 minDeploy from Gitlab failsI am getting the error: error sending request for url (https://backboard.railway-develop.app/graphRailway Github ActionHey i followed the blog online and am trying to deploy my railway app under a `backend/` directory i