a month ago
I get the above error even though I created a new app user with select,insert and update privileges and host %. The root user works fine.I have checked all the variables and they are correct n both MySql and app. Username and password are also correct
5 Replies
25 days ago
Remember that if you're trying to connect to the DB outside of Railway, you'll need to use the TCP proxy (docs).
That error usually means MySQL is rejecting the login, even if the username/password look right. A few common things to check (replace app_user and yourdb with your real username and database):
Make sure MySQL is matching the right user + host:
SELECT Host, User FROM mysql.user WHERE User = 'app_user';If there’s both app_user@localhost and app_user@%, it might be using the wrong one.
Try recreating the user cleanly (this fixes most cases):
DROP USER IF EXISTS 'app_user'@'%';
CREATE USER 'app_user'@'%' IDENTIFIED BY 'password';
GRANT SELECT, INSERT, UPDATE ON yourdb.* TO 'app_user'@'%';
FLUSH PRIVILEGES;If you’re on MySQL 8, your client may not support the default auth plugin. This often helps:
ALTER USER 'app_user'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;Double check the host you're connecting from, on Railway this is usually a remote host via the TCP proxy. Make sure the MySQL user is created with host
%(or the proxy IP) and that you're using the values inMYSQLHOST/MYSQLPORTfrom Railway’s environment variables.
If it still fails, try posting the output of SHOW GRANTS FOR 'app_user'@'%' .
25 days ago
Thank you @zackkrida for your reply ,first I apologize for not giving the correct context. I am trying to connect my app to the database and they are both deployed in the same project in railway. In my app I am using the the mysql host value "mysql.railway.internal" and the username and password. I can connect from outside railway with a mysql client using both root and my app user. However I am still getting this error when the app tries to connect to the DB from inside the railway network (same project):
Error connecting to MySQL: 1045 (28000): Access denied for user 'censususer'@'fd12:2e16:4dfb:1:4000:3b:8759:537' (using password: YES)
when I use your suggested query : SELECT Host, User FROM mysql.user WHERE User = 'app_user'; I get just one host which is %
as for the grants the user has select ,insert,and update for all the tables in my database
GRANT USAGE ON . TO censususer%
GRANT SELECT, INSERT, UPDATE, DELETE ON table1 TO censususer%
GRANT SELECT, INSERT, UPDATE, DELETE ON table2 TO censususer%
GRANT SELECT, INSERT, UPDATE, DELETE ON table3 TO censususer%
I also recreated the user again using the query you provided but still it is not connecting
Thank for your help and I look forward to your response.
Regards
K
25 days ago
Check thisstack overflow thread. It has multiple suggested solutions for this problem. It could help you solve it.
darseen
Check thisstack overflow thread. It has multiple suggested solutions for this problem. It could help you solve it.
24 days ago
Thanks for your response. I checked I don't have any anonymous users. I only have 2 users , root and one other and both have host%. This is strange , this should not be so difficult if I am connecting from within the railway network and from the same project
zackkrida
Remember that if you're trying to connect to the DB outside of Railway, you'll need to use the TCP proxy (docs).That error usually means MySQL is rejecting the login, even if the username/password look right. A few common things to check (replace app_user and yourdb with your real username and database):Make sure MySQL is matching the right user + host:SELECT Host, User FROM mysql.user WHERE User = 'app_user';If there’s both app_user@localhost and app_user@%, it might be using the wrong one.Try recreating the user cleanly (this fixes most cases):DROP USER IF EXISTS 'app_user'@'%'; CREATE USER 'app_user'@'%' IDENTIFIED BY 'password'; GRANT SELECT, INSERT, UPDATE ON yourdb.* TO 'app_user'@'%'; FLUSH PRIVILEGES;If you’re on MySQL 8, your client may not support the default auth plugin. This often helps:ALTER USER 'app_user'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; FLUSH PRIVILEGES;Double check the host you're connecting from, on Railway this is usually a remote host via the TCP proxy. Make sure the MySQL user is created with host % (or the proxy IP) and that you're using the values in MYSQLHOST / MYSQLPORT from Railway’s environment variables.If it still fails, try posting the output of SHOW GRANTS FOR 'app_user'@'%' .
24 days ago
Thank you @zackkrida for your reply ,first I apologize for not giving the correct context. I am trying to connect my app to the database and they are both deployed in the same project in railway. In my app I am using the the mysql host value "mysql.railway.internal" and the username and password. I can connect from outside railway with a mysql client using both root and my app user. However I am still getting this error when the app tries to connect to the DB from inside the railway network (same project):
Error connecting to MySQL: 1045 (28000): Access denied for user 'censususer'@'fd12:2e16:4dfb:1:4000:3b:8759:537' (using password: YES)
when I use your suggested query : SELECT Host, User FROM mysql.user WHERE User = 'app_user'; I get just one host which is %
as for the grants the user has select ,insert,and update for all the tables in my database
GRANT USAGE ON . TO censususer%
GRANT SELECT, INSERT, UPDATE, DELETE ON table1 TO censususer%
GRANT SELECT, INSERT, UPDATE, DELETE ON table2 TO censususer%
GRANT SELECT, INSERT, UPDATE, DELETE ON table3 TO censususer%
I also recreated the user again using the query you provided but still it is not connecting
Thank for your help and I look forward to your response.
Regards
K
Status changed to Awaiting User Response sam-a • 24 days ago
17 days ago
This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!
Status changed to Solved Railway • 17 days ago
