This worked for me:
https://blog.dotkam.com/2007/04/10/mysql-reset-lost-root-password/
Step 1: Stop MySQL daemon if it is currently running
ps -ef | grep mysql - checks if mysql/mysqld is one of the running processes.
pkill mysqld - kills the daemon, if it is running.
Step 2: Run MySQL safe daemon with skipping grant tables
mysqld_safe --skip-grant-tables &
mysql -u root mysql
Step 3: Login to MySQL as root with no password
mysql -u root mysql
Step 4: Run UPDATE query to reset the root password
UPDATE user SET password=PASSWORD("value=42") WHERE user="root";
FLUSH PRIVILEGES;
In MySQL 5.7, the 'password' field was removed, now the field name is 'authentication_string':
UPDATE user SET authentication_string=PASSWORD("42") WHERE
user="root";
FLUSH PRIVILEGES;
Step 5: Stop MySQL safe daemon
Step 6: Start MySQL daemon