0

yii2 database connection to mysql on a mac os SQLSTATE[HY000] [2002] No such file or directory Hello, I would apprciate any help. Im using the prebuilt yii2 template and im trying to connect my local mysql database to it but its not working. ive tried everything in this stackoverflow page SQLSTATE[HY000] [2002] No such file or directory in yii2 but no luck.

<?php

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

    // Schema cache options (for production environment)
    //'enableSchemaCache' => true,
    //'schemaCacheDuration' => 60,
    //'schemaCache' => 'cache',
]; ?>
ds007
  • 35
  • 2
  • 9
  • 1
    Normally, this problem can be caused by using a host value of `localhost` rather than `127.0.0.1` in the DSN: https://stackoverflow.com/questions/36930536/sqlstatehy000-2002-no-such-file-or-directory-in-yii2 You're not doing that, I'm not sure what's causing this. – Nick ODell Oct 09 '22 at 00:04
  • Hello @NickOdell. you are correct something was wrong with my mysql permissions. and I just used localhost and fixed the problem. – ds007 Oct 17 '22 at 18:52

0 Answers0