SQLSTATE[HY000] [2002] yii2 中没有这样的文件或目录

2022-08-30 23:51:05

我使用
.

(在phpmyadmin写作)。ubuntu 16.04.PHP Version 7.0.4-7ubuntu2Apache/2.4.18 (Ubuntu)PHP extension: mysqli

我从中升级了我的ubuntu,但我有这个错误:15.10 to 16.04

我的项目在我的服务器中正确运行,但我无法在我的操作系统中运行它:

Database Exception – yii\db\Exception
SQLSTATE[HY000] [2002] No such file or directory
↵
Caused by: PDOException
SQLSTATE[HY000] [2002] No such file or directory

in /var/www/html/iicitySite/vendor/yiisoft/yii2/db/Connection.php at line 579

答案 1

将“本地主机”更改为“127.0.0.1”作为主机

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

答案 2

对于 MAMP 用户,解决方案是

'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',
    ],
],

推荐