SQLSTATE[HY000] [2002] No such file or directory in yii2

Changing "localhost" to "127.0.0.1" as your host

return [
    'components' => [
        'db' => [
            'class' => 'yii\db\Connection',    
            'dsn' => 'mysql:host=127.0.0.1;dbname=abc',
            'username' => 'root',
            'password' => '',
            'charset' => 'utf8',
        ],

For MAMP users solution is

'components' => [
    'db' => [
        'class' => 'yii\db\Connection',
        'dsn' => 'mysql:host=localhost;port=8889;dbname=mydbname;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock',
        'username' => 'myuser',
        'password' => 'mypassword',
        'charset' => 'utf8',
    ],
],

Hope this answer will help You:

Change the Host name from localhost to 127.0.0.1

This is inside backend\common\config\main-local.php

Now you run php yii migrate .

Hope, It will successfully create the tables in Database