If for some reason you have forgotten the root password for an existing mysql installation you can recover the account by starting mysqld with the --skip-grant option. This is roughly analogous to starting a Unix system in single user mode.
First thing, shut down the running instance and then restart it directly
$ sudo -u <mysql_user> mysqld_safe --skip-grant-tables --skip-networking
The --skip-networking option is important, as by skipping the grant tables, any user can connect to the running mysqld service, will full permissions.
Once you've started the server up, login without a password, and issue an update query to the mysql.user table.
$ mysql -uroot mysql mysql> UPDATE user SET password=password('newpassword') WHERE User = 'root'
Close down mysqld and restart. You're good to go.