#Can I use an Intranet to access mysql

67 messages · Page 1 of 1 (latest)

fickle ivy
#

My service and mysql are both deployed on railway. Can I use the Intranet to access mysql?

toxic gyroBOT
#

Project ID: 95472512-a46f-4dd2-8837-da96caffebbc

fickle ivy
#

95472512-a46f-4dd2-8837-da96caffebbc

orchid prism
#

you can't at the moment, you have to access services and plugins from their public addresses, even if both in the same project

#

though internal networking is coming!

fickle ivy
#

@orchid prism Currently i always encounter timeout problem, read tcp 172.17.2.122:49660->35,199.165.80:7806: i/o timeout problem, is this a public network problem?

orchid prism
#

are you connecting to the database with the variable references?

fickle ivy
#

yes

#

use go orm connect it

orchid prism
#

show me a screenshot of the service variables and how you are using them in your code

fickle ivy
#

I also found that when using the local command line, the connection would be disconnected after a while

orchid prism
#

you arent using environment variables

fickle ivy
#

Oh, yes, I wrote the configuration link in the code

orchid prism
#

show me please

fickle ivy
#

The screenshot above is the link configuration I used

#

I get this error a lot in my local environment

orchid prism
#

show me the dsn variable

fickle ivy
orchid prism
#

you arent using environment variables

fickle ivy
#

Do I have to use the railway environment variable? Can I write it in the go service configuration file?

orchid prism
#

not recommended

fickle ivy
#

Thank you. I'll change it to use environment variables

orchid prism
#

also, please dont build your own dsn like that, use the MYSQLDATABASE variable

fickle ivy
#

Do you mean to recommend that I build all the tables under the railway database? Can I create my own database for use?

#

I created a database stock that can be queried in mysql-client, but cannot be found in the railway dashboard.

orchid prism
#

please just one thing at a time, let me know when you're using environment variables, and have removed all database credentials or domains from plain text files

fickle ivy
#

Can I directly refer to the environment variables exposed by the mysql plugin in my service? Do I need to configure it to my service in railway?

orchid prism
#

you need to setup variable references or your service will not have access to the database

orchid prism
fickle ivy
#

Sorry, I didn't understand you at first. It's my fault

#

😫

orchid prism
#

please read that docs link i sent you, and once you think you have it setup, show me a screenshot of the service variables

fickle ivy
#

This is right?

orchid prism
#

what is ENV for?

fickle ivy
#

This is the environment variable that determines my service, prod or local

orchid prism
#

RAILWAY_ENVIRONMENT exists

#

but thats just an fyi, your service variables look good

#

now use them in code

#

os.Getenv("VARIABLE_NAME")

fickle ivy
#

I finished it.

#

I use a self-created database, and I need to migrate the data if I need to switch to railway

orchid prism
#

you can do this lol

if os.Getenv("RAILWAY_ENVIRONMENT") == "production" {
    // code
}
fickle ivy
#

Ok, I will modify it later. Does this currently can resolve the problem of occasional timeout?

orchid prism
#

no im just getting distracted

#

does you code now connect the the database at least?

fickle ivy
#

Yes, it can connect success.

orchid prism
#

so that issue is solved

fickle ivy
#

But my problem is an accidental timeout, which could have been connected successfully before.

orchid prism
#

does it time out during connection?

fickle ivy
#

No, most of the time it happens when I update or insert

#

So I'm wondering if it's a problem with an unstable public network connection.

#

2023/04/15 03:45:34 /go/stock-web-be/dao/db/db.go:68 invalid connection

orchid prism
#

do you have this code in a public repo?

fickle ivy
#

no, but I can provide this code

orchid prism
#

if you could put it into a repo that would be very helpful

fickle ivy
#

Sorry, I seem to know why the connection is invalid. It should be that I changed the database to the railway to trigger create table

orchid prism
#

let me know how that goes

#

because this is definitely just a simple code issue

fickle ivy
#

db.AutoMigrate(&Permission{}) That problem is triggered the first time a table is created.

#

There should be no problem now. We can discuss it when I timeout again. Sorry to bother you today.