If you make a mistake whilst changing the host from localhost to an incorrect IP address you can find yourself completely locked out of mysql. This is also true if you forget your root mysql password. The first scenario is more likely if you use a third party tool such as webmin or phpmyadmin.
Simply login to shell / terminal and close mysql if it is running.
ps ax
note the pid of mysql and then kill the process (this example assumes it was running on 1506)
kill 1506
Now, re-start mysql as follows
mysqld_safe --skip-grant-tables
This will start mysql again with no privileges set so you can change the hostname or reset the password as needed.
UPDATE mysql.user SET Host='localhost' where user='root';
FLUSH PRIVILEGES;
If you have webmin installed once you have started in safe mode you can use the gui to make any necessary changes. Then restart mysql.