1

I created a new DigitalOcean droplet and stupidly deleted the env file in the root to clear it out so I could setup my application. The only recorded place that had the root user's password.

I'm trying to reset said password but literally none of the questions on StackOverflow or here work and I don't know why.

I tried to follow this guide on the mysql docs page by running this command:

kill `cat /var/lib/mysql/my-app-1.pid`

It then says to add the following to a new file:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password123';

Then run the following command:

$ mysqld --init-file=/home/reset-root-pass &

That doesn't work though. When I try and log in to mysql it says the password is still wrong. I even tried this answer from StackOverflow and I still can't log in.

sudo service mysql stop
sudo mysqld_safe --skip-grant-tables
sudo service mysql start
sudo mysql -u root
sql> use mysql;
sql> show tables;
sql> describe user;
sql> update user set authentication_string=password('1111') where user='root';
sql> FLUSH PRIVILEGES;
sql> 

Can someone help me get this password reset, please?

Cbhihe
  • 2,701
  • I take it you are talking about the *mysql root passwd*, not your host's system root passwd. Did you check the result of sudo service mysql stop ? Nowadays most system are based on systemd and so use sudo systemctl stop <service_name> to stop (also to start or to verify the status of) a service. – Cbhihe May 09 '22 at 20:09
  • 2
    Note the trick here is to start mysql in safe mode. eg: sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables – Philip Couling May 09 '22 at 20:12

0 Answers0