I’ve been setting up a LEMP server, Nginx Mysql PHP, on Ubuntu and lost my root mysql password. Here’s what I did to reset the password in Terminal.
After logging into my server via SSH on Terminal I ran the following lines in Terminal.
# /etc/init.d/mysql stop
# mysqld_safe --skip-grant-tables &
$ mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql start
$ mysql -u root -p
I found this solution in an answer by Benjamin Manns to a StackOverflow question here.
