I tried Yii Framework migration by using yiic in console. when yiic migrate database, it try to connect to db following the information that be configured like below:
        'db'=>array(
   'connectionString' => 'mysql:host=localhost;dbname=YOURDBNAME',
   'emulatePrepare' => true,
   'username' => 'DBUSER',
   'password' => 'DBPASS',
   'charset' => 'utf8',
  ),
and faced an exception:
[2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock)
Based on error message I checked the location of mysql.sock file in my computer, by using the following command in terminal (I typed sudo to make sure I have sufficient permission)
sudo find /  -name mysql.sock

Oops ! It's in  '/Applications/MAMP/tmp/mysql/mysql.sock' 


1. Resolve in  Yii Framework configure file 

  'db'=>array(
   'connectionString' => 'mysql:host=localhost;dbname=YOURDBNAME;
    unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock',
   'emulatePrepare' => true,
   'username' => 'DBUSER',
   'password' => 'DBPASS',
   'charset' => 'utf8',
  ),

As you can see, I add more parameter 'unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock' to set the unix_socket option for connectionString. It worked !

But when you contribute with other in the same project and have to synchronize source code with other ( by git or svn) , it may be make some confuse if their mysql.sock file is located in different path. So, let's turn to next solutions

2. Create new link for mysql.sock in your system 

 We need to check /var/mysql folder has existed or not.
cd /var
if it does not existed use
mkdir  /var 
to create new folder
and
cd mysql
if not
mkdir mysql

Using ln command to create new link

sudo ln -s  {SOURCE} {DESTINATION}
In my computer, the command like this:
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

It's worked, too !

3. Make some configuration in php.ini file

Open the php.ini file and find this line:
mysql.default_socket
And make it
mysql.default_socket = /path/to/mysql.sock
Yeah ! It's worked and I don't like this way so much ^^.

 There are 3 ways to resolve this exceptions that I mentioned above ! Good luck !