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
Project ID:
28e5bbc5-449a-46ba-80bd-62e16c4eed9b
You might find these helpful:
- Hello, I come here for help on how can I connect to a SQL server database with NodeJS and Express
- Error connecting MySQL database with Express
- I can't connect to the database, from the servers for hosting.
⚠️ experimental feature
Project ID: 28e5bbc5-449a-46ba-80bd-62e16c4eed9b
are you getting this error when both the python script and mysql instance are running on railway?
yes
can you show me a screenshot of your service variables?
should I reveal them?
no no, please show the service variables though, those are the plugin variables
ah i see, should I be manually adding those variables here?
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
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.
look into database migration
ill do that