Problem connecting to mysql through terminal and through mamp

Can anyone help? I don’t have much experience of solving this kind of issue.

I can no longer connect to mysql through mamp - the light remains red (the apache light is green).
In the past typing ‘killall -9 mysqld’ has done the trick and I have been able to connect to mysql through mamp afterwards.

In addition, I am now also unable to connect to mysql through the terminal window. I get the error message

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/Applications/MAMP/tmp/mysql/mysql.sock’ (2)

The only changes I’ve made have been to the file in the folder phpMyAdmin, as instructed on page 315 of ‘Build your own database driven web site’. (I reverted my changes back but I still get this error message.)

Any ideas how I can connect to the database again and get mamp working?