#MySQL DB not connecting to railway

21 messages · Page 1 of 1 (latest)

steady sigil
#

My db wont connect with railway when I deploy. Works fine on my local computer. Here is the error message:
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '0.0.0.0' ([Errno 111] Connection refused)")
10.10.10.6 - - [09/Jan/2023 23:54:12] "POST /login HTTP/1.1" 500 -

Here is my code:
connection = pymysql.connect(host = '0.0.0.0',
user = 'root',
password = 'root',
db = db,
charset = 'utf8mb4',
cursorclass = pymysql.cursors.DictCursor,
autocommit = True)

Would appreciate some help!

unborn islandBOT
#

Project ID: ae150009-5e1d-4b9d-9fbc-f853b219385f

#

No search results found.

steady sigil
#

Project ID : ae150009-5e1d-4b9d-9fbc-f853b219385f

serene beacon
#

Railway services aren't all on the same host. Your app is looking at 0.0.0.0, which is not where your database is

#

If your db is hosted on Railway, use its link. If it's hosted locally, use your ip

steady sigil
#

Okay thanks. I'll give it a try

steady sigil
#

So my database is hosted on my local computer. Just to clarify, for it to work on railway deployment I should use my computer ip address for the host?

serene beacon
#

If your network is exposed, yes

#

otherwise, use the database that you’re hosting on Railway locally for testing

steady sigil
#

I tried using my ip address for the database host, 127.0.0.1. and I'm still getting a "cant connect to MySQL server on '127.0.0.1' " error

#

Do I need to create a MySQL db on railway for the db to connect? Or is railway able to use the MySQL database I have already setup on my local computer to connect? I'm wondering because when I look at the railway docs, it only gives information related to a MySQL db that is built and hosted on railway.

serene beacon
#

127.0.0.1 is the address of your local pc, that’s not your actual ip

#

Railway will not be able to use your local database unless you port forward your router. it’s not as simple as just clicking go

#

it’s in your best interest to host your database. Doesn’t have to be on Railway

steady sigil
#

Okay I see. So I should use a hosting platform online to host my database?

serene beacon
#

Yes

steady sigil
#

Okay I think I understand now. I didn't know that. Thanks for your help!

serene beacon
#

No problem

steady sigil
#

Quick question if I'm able to ask. I successfully deployed a django app on railway with the SQLite db that it is built with. How come you dont have to host the db with django? Just curious

placid terrace
#

every time you redeploy your app, the sqlite db inside will be destroyed, since railway's container storage is ephemeral