Connect Python Script to MySQL

Hi there, I am simply trying to connect a python script to a MySQL instance but I'm getting this error: _mysql_connector.MySQLInterfaceError: Can't connect to MySQL server on 'localhost:7140' (99) See the screenshot for my connection code.
15 Replies
Percy
Percy2y ago
Project ID: 28e5bbc5-449a-46ba-80bd-62e16c4eed9b
Weatherman
WeathermanOP2y ago
Project ID: 28e5bbc5-449a-46ba-80bd-62e16c4eed9b
Brody
Brody2y ago
are you getting this error when both the python script and mysql instance are running on railway?
Weatherman
WeathermanOP2y ago
yes
Brody
Brody2y ago
can you show me a screenshot of your service variables?
Weatherman
WeathermanOP2y ago
Weatherman
WeathermanOP2y ago
should I reveal them?
Brody
Brody2y ago
no no, please show the service variables though, those are the plugin variables
Weatherman
WeathermanOP2y ago
Weatherman
WeathermanOP2y ago
ah i see, should I be manually adding those variables here?
Brody
Brody2y ago
no never add the database variables manually, click the variable references link button, but read this before you get into that, read this https://docs.railway.app/develop/variables#reference-variables
Weatherman
WeathermanOP2y ago
Ok it works thanks. Another question, if I have a database table that I want to have pre-loaded without the program needing to create it, what would be a good way for me to do that? Or should I set it up in the code like: if table exists, continue, if not, create it.
Brody
Brody2y ago
look into database migration
Weatherman
WeathermanOP2y ago
ill do that
Want results from more Discord servers?
Add your server