#Timed out error connecting backend to MySQL database

228 messages · Page 1 of 1 (latest)

solemn bobcat
high basinBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

tall garnetBOT
#

Project ID: N/A

solemn bobcat
dim epoch
potent quartz
#

in your mysql.createConnection just use a database url, much easier, since you left out the port variable

solemn bobcat
solemn bobcat
potent quartz
#

can you show us your raw service variables, and make sure to hide anything sensitive please

solemn bobcat
solemn bobcat
solemn bobcat
#

I took a look at the mysql documentation and it left me more confused than before

solemn bobcat
solemn bobcat
# potent quartz this is still applicable

I'm still very much a beginner so I can't figure out what the property name is for the createConnection function. I got this error and from guess attempting. I'm trying to figure it out right now though

Ignoring invalid configuration option passed to Connection: url. This is currently a warning, but in future versions of MySQL2, an error will be thrown if you pass an invalid configuration option to a Connection

Server is running on port 7698

Error connecting to mySQL: Error: connect ETIMEDOUT

at Connection._handleTimeoutError (/app/node_modules/mysql2/lib/connection.js:205:17)

at listOnTimeout (node:internal/timers:569:17)

at process.processTimers (node:internal/timers:512:7) {

errorno: 'ETIMEDOUT',

code: 'ETIMEDOUT',

syscall: 'connect',

fatal: true

}
const connection = mysql.createConnection({
    host: process.env.HOST,
    user: process.env.USER,
    password: process.env.PASSWORD,
    database: process.env.DATABASE,
    url: process.env.URL
});
potent quartz
#

show me a screenshot of your railway service variables

solemn bobcat
potent quartz
#

those are the plugin variables, please show me the service variables

solemn bobcat
potent quartz
#

can you show me those in the raw editor, also hiding anything sensitive

solemn bobcat
#

by the way I used the plugin variables in my server.js file not the service variables in the env file

#

was this my mistake?

#

you got it

potent quartz
#

yes, but it is not the only mistake, so let's take this one thing at a time so we can come to a total solution

solemn bobcat
#

This is the env file it has the plugin variables from the sql service. I'm guessing I was suppose to put in the service variables from the website service but I haven't changed anything yet

potent quartz
#

no you weren't, please make sure you do not have that file in your repository

solemn bobcat
#

I have gitignore setup

potent quartz
#

and please show me the raw variable editor for your service, hiding anything important

solemn bobcat
#

For the sql service or the website service?

#

I'm not sure what you mean by raw variable editor?

potent quartz
#

for whatever service is using the database

solemn bobcat
#

Oh okay

potent quartz
solemn bobcat
#

Ah

potent quartz
#

the mysql database, it is in the same railway project?

solemn bobcat
#

Sorry this is my first time messing with back end stuff

potent quartz
#

nope that's good, that's how it should be

solemn bobcat
#

Oh okay well the env file has the plugin vars from the sql service so should I be replacing them with the service vars from the website service?

potent quartz
solemn bobcat
#

Oh okay

solemn bobcat
potent quartz
#

wdym lost it

#

you should use reference variables, please read the docs page I linked and then show me the raw variables again when done please

solemn bobcat
# potent quartz wdym lost it

Basically I started deleting to put them back in as ref vars but then I realized the photo was edited with the password omitted so I just made my own password. The rest I did turn into ref vars and I got the same error again

potent quartz
#

don't worry about the error yet, I knew it still wouldn't work

#

and you can't just make up your own password, the password needs to be a reference too

solemn bobcat
#

I'm fine I'm just sweating the lost SHA password 😂

#

Well it's set up like a ref var but how do i reset a password for the website service?

potent quartz
#

and actually, none of those are reference variables, please read the docs I linked

solemn bobcat
#

Okay I'll take a look again my bad

#

I believe I did it correctly this time. It's basically what the dropdown shows for the value in accordance to what was set as the var name right?

#

Which was also just a dropdown selection?

potent quartz
#

idk let's see the raw variables

solemn bobcat
#

Is this correct?

potent quartz
#

okay I think that looks good, now you need to go and click the little eye icon on each of those variables to make sure they are displaying their proper values

solemn bobcat
#

will do

#

They are

solemn bobcat
potent quartz
#

nope

solemn bobcat
#

Oh okay

potent quartz
#

and actually railway makes .env files obsolete

#

but that's a bit out of the scope of this particular help thread

#

now in your mysql.createconnection thing, use all those environment variables

#

show me the code before you push it please

potent quartz
#

I like the out of the box thinking, but that syntax is only for railway, you still have to use process.env in your code

solemn bobcat
#

lol

#

okay so i will use that but what do I put in the env file then? i was thinking this was the wrong teh second i screenshotted it

potent quartz
solemn bobcat
#

Yeah the way it was set up before the screenshot was simiilar

potent quartz
potent quartz
#

we will come back to the .env file topic in a bit, for now, delete your .env file

potent quartz
#

and show me your new connection code once you've done that

solemn bobcat
#

Well nothings changed except I reverted the copy paste oh okay I saw your edit one sec

potent quartz
#

you are not using all the needed variables, you must use all the database variables you had in railway
with the exception of the database url variable, you don't need to use that

solemn bobcat
#

It was actually at the top of my file as a separate const variable I just threw it in

#

oh shit hold up i gotta delete the semi colon

potent quartz
#

the object field names are correct, but you need to use the variable names from railway

solemn bobcat
#

Okay will do rn

potent quartz
#

I said the object field names are correct, you did the exact opposite of what I'd thought you'd do lol

solemn bobcat
#

Oh

#

so change the values not the properties?

#

with the values from the ref vars on railway? wouldnt that expose the sensitive info if my repo was public?

#

its private btw

#

I'm sorry I'm literally a noob except for front end stuff not including js

potent quartz
#

host: process.env.MYSQLHOST

solemn bobcat
#

Oh okay

potent quartz
#

makes sense?

solemn bobcat
#

yessir

solemn bobcat
potent quartz
#

looks correct

#

do you have the railway cli installed?

solemn bobcat
#

yup

#

oh i see whats next

#

cause i tried literally everything

potent quartz
#

what's next?

solemn bobcat
#

use the cli to link the database then railway up?

#

if i remember correctly

potent quartz
#

nope, you deploy from github, no railway up

solemn bobcat
#

lol so why ask if i have the cli installed?

potent quartz
#

well something comes next, but it's not what you said lol

#

do you have your project linked to the service we have been adding reference variables to?

solemn bobcat
#

Okay so Ima commit push this

#

yeah the websites live already

potent quartz
#

nope

solemn bobcat
#

oh okay i wont commit push this

potent quartz
#

slow your horses, we are tackling the .env thing, or the lack there of .env thing

solemn bobcat
#

Right I forgot about that

potent quartz
#

do you have the cli linked to your railway project and service from the folder you are currently in?

solemn bobcat
#

I can access it from the terminal on vscode which has the repo opened locally

potent quartz
#

not what I asked

#

do you have the railway cli installed

solemn bobcat
#

On my laptop yeah

potent quartz
#

do you have the cli linked to your railway project and service from the folder you are currently in?

#

this has nothing to do with github

solemn bobcat
#

I believe no

#

I have the cli installed and I can access it from the terminal but its not linked to the railway project

potent quartz
#

link it

solemn bobcat
potent quartz
#

now link a service railway service

solemn bobcat
potent quartz
#

run railway variables and do you see all the database variables properly printed?

solemn bobcat
#

Yessir

#

It's set up on a 2 column table and accurate

potent quartz
#

okay now are you starting to see how the cli can replace your .env file

solemn bobcat
#

Yeah I am actually

potent quartz
#

the final touch is using railway run <the command you normally use to start your app locally>
this will run your app with the environment variables available, no variables will be written to disk

#

see how that's better than a plaintext file with your database credentials in it?

solemn bobcat
#

Yeah it's a smoother process maybe longer but smoother. Should I push the changes I made to github first or just leave as is?

#

Actually its only longer cause this is the first time I'm doing it lol

potent quartz
#

well go and use railway run first, gotta check that your code does work

solemn bobcat
#

okay

potent quartz
#

I'd like to note that if the cli ever tells you to do railway up do not do it, ignore that message, that message is a bug and should never be printed

solemn bobcat
potent quartz
#

🥳🥳🥳

solemn bobcat
#

Thank you so much man there's no way I would've been able to pull this off I had no idea about the ref vars THANK YOU!

#

Cheers mate

potent quartz
#

yeah I told the team they need better docs on that, reference variables catch even experienced devs off guard, so don't feel bad for not understanding

solemn bobcat
#

Thank you man I'll only be a noob for so much longer but I'm glad this final hurdle is done

potent quartz
#

awesome, best of luck!

#

(you can push to github now lol)

solemn bobcat
#

Hey I'm sorry for bothering again but I don't get any error messages in the deploy log I actually get a success message about the database making a connection yet the server fails to load the website now.

#

I think I should make a new support thread or whatever its called I will if it's not fit to put it here

potent quartz
#

what is that chrome theme 💀

solemn bobcat
potent quartz
#

this is where it's at

#

off topic though lol

solemn bobcat
#

Honestly there's no passwords to hide I may as well temporarily make the repo public

#

But yeah its express

potent quartz
#

sounds good

solemn bobcat
#

Okay I'll do that and link the github link real quick

solemn bobcat
potent quartz
#

10/10 readme

solemn bobcat
#

hahahahahaa

potent quartz
#

I'm confused

potent quartz
#

but the package.json in that repo does not have a start script?

solemn bobcat
#

Yeah I'm confused about that too honestly

#

Also I have no idea if this new problem is big or tiny cause it just doesnt give an error msg

potent quartz
#

and railway would error out by default if you don't have a start script in your package.json

#

check the service settings, do you have a start command set in there?

solemn bobcat
#

It's worked for a couple days now I have npm run start in the settings for the website service on railway as the start command

potent quartz
#

what's it set to

solemn bobcat
#

npm run start

potent quartz
#

but you don't have a start script in your package.json

#

are you sure this is the same repo that your service is set to deploy from

solemn bobcat
#

Yeah I think I'm gonna make it I believe it starts up the express server

#

I'm 100% sure

#

If the pages could atleast load you could see for yourself

potent quartz
#

but you don't have a start script in the package.json

#

you can't run npm run start without a start script

solemn bobcat
#

Yeah I noticed this odd situation awhile ago and kind of just ignored it

potent quartz
#

I can't ignore it

solemn bobcat
#

No I know it's an issue now I can make a start script but not sure exactly what the value would be. I believe it would be node server.js

potent quartz
#

that's correct

#

do that, then remove the start command from the service settings

#

make sure you click the checkmark when you remove the start command

solemn bobcat
#

Okay

potent quartz
solemn bobcat
#

I deleted it in railway settings and now I'm gonna commit push the addition of it in my package json file

#

Oh okay I'll do that too then commit push

#

Same change for the console log under what you highlighted?

potent quartz
solemn bobcat
#

where it says process.env.PORT?

potent quartz
solemn bobcat
#

Wait so that link I copy paste it into the gitignore file or put it in a type of file then link the git ignore file to that file?

potent quartz
#

the contents of that link

solemn bobcat
#

in the gitignore file got it okay

potent quartz
#

yep

solemn bobcat
#

Okay I'm boutta push this to the repo

solemn bobcat
# potent quartz yep

Thanks again it works now I just have to deal with some bugs on the front end with the contact form but I got somewhat far on my own so Ima try to tackle them on my own

potent quartz
#

what kind of frontend is it?

solemn bobcat
potent quartz
#

yes lol but what framework

solemn bobcat
#

Just small things like before I had the index.js file with a fetch method to send form data to the back end so it can be sent as an automated email but i quit that for a database approach because i couldn't figure it out and didn't want to deal with azure (outlook email) but the code stayed the same so i gotta update it for this database along with the app.post method i gotta update that too a bit

solemn bobcat
#

just tailwind css, express, node?

potent quartz
#

for the frontend? no react, Vue, etc?

solemn bobcat
#

Nope I kind of want to learn vanilla so I know whats going on cause things are abstracted as it is and I'm still learning

potent quartz
#

very good take

#

how are you serving the frontend?

solemn bobcat
#

express static middleware I believe

#

I sort of don't know what I'm saying just saying lol

#

It's in the repo if you want to look

potent quartz
#

oh I see now, not the most performant but definitely adequate for a beginner

solemn bobcat
potent quartz
#

oh no that's definitely not what I was getting at

solemn bobcat
#

Oh okay

potent quartz
#

I'm talking about just serving your frontend with an actual web server and not express middleware, but don't worry about that the middleware is perfectly fine for now

solemn bobcat
#

True I'll learn more as I go on

potent quartz
#

sounds good!!

#

I wish you luck in your development adventures

solemn bobcat
#

Appreciate your help again Ima go take care of these bugs now 🙏🏽 peace