Cannot connect to MySQL database after regenerating password
gfkacid
FREEOP

a month ago

I regenerated password on my MySQL database. Then, after updating the database url env variable on my backend service with the new password, subsequent deployments are crashing with error:

Error: P1000: Authentication failed against database server, the provided database credentials for root are not valid.

Solved$10 Bounty

4 Replies

Railway
BOT

a month ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


Time for the great guide of all time

Before you do any of this, disable all public access domains. Just in case.

  1. Install the Railway CLI. You can do so here: https://docs.railway.com/guides/cli

  2. Copy the SSH command by right clicking the PostgreSQL service

  3. Once you're in, type in the following command: (Copy paste this EXACTLY as written.)

    sed -i 's/host all all all scram-sha-256/host all all ::\/0 trust/' /var/lib/postgresql/data/pgdata/pg_hba.conf

  4. Redeploy your database.

  5. Use the SSH command again, and once you're in, type psql.

  6. Type the following SQL command. my_password should be replaced with whatever it actually says in your variables tab for your password (Probably under the PGPASSWORD variable.)

    ALTER USER postgres with password 'my_password';

  7. Type exit

  8. Reset your authentication settings with the following command:

    sed -i 's/host all all ::\/0 trust/host all all all scram-sha-256/' /var/lib/postgresql/data/pgdata/pg_hba.conf

  9. Redeploy your database once again. You have now changed the password.

Let me know if this works!


samgordon

Time for the great guide of all time⠀Before you do any of this, disable all public access domains. Just in case.⠀Install the Railway CLI. You can do so here: https://docs.railway.com/guides/cliCopy the SSH command by right clicking the PostgreSQL serviceOnce you're in, type in the following command: (Copy paste this EXACTLY as written.)sed -i 's/host all all all scram-sha-256/host all all ::\/0 trust/' /var/lib/postgresql/data/pgdata/pg_hba.confRedeploy your database.Use the SSH command again, and once you're in, type psql.Type the following SQL command. my_password should be replaced with whatever it actually says in your variables tab for your password (Probably under the PGPASSWORD variable.)ALTER USER postgres with password 'my_password';Type exitReset your authentication settings with the following command:sed -i 's/host all all ::\/0 trust/host all all all scram-sha-256/' /var/lib/postgresql/data/pgdata/pg_hba.confRedeploy your database once again. You have now changed the password.⠀Let me know if this works!

gfkacid
FREEOP

a month ago

do you have handy a flavor of this guide for MySQL instead of Postgre?


gfkacid
FREEOP

a month ago

deleting database and creating a new one solved it. Apparently the way MySQL is containerized, password regeneration doesn't propagate


Status changed to Solved noahd about 1 month ago


Loading...