Forgetting passwords isn't generally a good idea. It does happen, though, and if it happens to your MySQL server, this is the process you need to follow in order to recover it.
First of all, you need to stop the running MySQL server. You need to be root on your system, then:
# /etc/init.d/mysql stop
Now, we need to make a text file called an init file. The contents of this file will be executed in a moment when we restart the MySQL server in a special way. So, create a new text file in your home folder and place this in the file:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpassword');
Obviously, substitute in your desired password (leaving the quotes intact). Save the file as passwordinit.
Now, we need to start the MySQL server with this init file. Still as root on the system, run:
# mysqld_safe --init-file=~/passwordinit &
As soon as you press Enter, the password has been changed. Now I recommend restarting the MySQL server in the normal way, as follows:
# /etc/init.d/mysql restart
And that's it. Be more careful next time.