MySQL configured to use tunneled localhost port

Yes, I've noticed this myself; it's not particular to Rails. I have to do this when using CocoaMySQL to connect to my remote database via ssh tunnel. I sure would like to know why it works this way too... Is "localhost" just a magic keyword for using the socket?

--Andrew Vit