Start MySQL server without user authentication and networking, this allows to connect without credentials from localhost only. Run using the same user account the MySQL daemon runs under to avoid permission problems (probably, sounds reasonable doesn’t it?)
sudo -u mysql_account mysqld_safe --skip-grant-tables --skip-networking &
Connect to MySQL with no credentials:
mysql
Reload authentication:
FLUSH PRIVILEGES;
Change root password:
MySQL 5.7.6 and later:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
MySQL 5.7.5 and earlier:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
From here: http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html