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
Percy16mo ago
Project ID: 28e5bbc5-449a-46ba-80bd-62e16c4eed9b
Weatherman
Weatherman16mo ago
Project ID: 28e5bbc5-449a-46ba-80bd-62e16c4eed9b
Brody
Brody16mo ago
are you getting this error when both the python script and mysql instance are running on railway?
Weatherman
Weatherman16mo ago
yes
Brody
Brody16mo ago
can you show me a screenshot of your service variables?
Weatherman
Weatherman16mo ago
Weatherman
Weatherman16mo ago
should I reveal them?
Brody
Brody16mo ago
no no, please show the service variables though, those are the plugin variables
Weatherman
Weatherman16mo ago
Weatherman
Weatherman16mo ago
ah i see, should I be manually adding those variables here?
Brody
Brody16mo 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
Weatherman16mo 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
Brody16mo ago
look into database migration
Weatherman
Weatherman16mo ago
ill do that