服务器错误 yiidbException SQLSTATE[HY000] [2002] No such file or directory ###'xxx是项目根目录' #0 xxx/vendor/yiisoft/yii2/db/Connection.php(928): yiidbConnection->open() #1 xxx/vendor/yiisoft/yii2/db/Connection.php(915): yiidbConnection->getMasterPdo() #2 xxx/vendor/yiisoft/yii2/db/Schema.php(483): yiidbConnection->getSlavePdo() #3 xxx/vendor/yiisoft/yii2/db/Connection.php(824): yiidbSchema->quoteValue('1') #4 xxx/vendor/yiisoft/yii2/db/Command.php(175): yiidbConnection->quoteValue('1') #5 xxx/vendor/yiisoft/yii2/db/Command.php(866): yiidbCommand->getRawSql() #6 xxx/vendor/yiisoft/yii2/db/Command.php(887): yiidbCommand->logQuery('yii\db\Command:...') #7 xxx/vendor/yiisoft/yii2/db/Command.php(376): yiidbCommand->queryInternal('fetch', NULL) #8 xxx/vendor/yiisoft/yii2/db/Query.php(253): yiidbCommand->queryOne() #9 xxx/vendor/yiisoft/yii2/db/ActiveQuery.php(294): yiidbQuery->one(NULL) #10 xxx/modules/course/controllers/CourseController.php(249): yiidbActiveQuery->one() #11 [internal function]: appmodulescoursecontrollersCourseController->actionSubscribe('1') #12 xxx/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array) #13 xxx/vendor/yiisoft/yii2/base/Controller.php(156): yiiaseInlineAction->runWithParams(Array) #14 xxx/vendor/yiisoft/yii2/base/Module.php(523): yiiaseController->runAction('subscribe', Array) #15 xxx/vendor/yiisoft/yii2/web/Application.php(102): yiiaseModule->runAction('course/course/s...', Array) #16 xxx/vendor/yiisoft/yii2/base/Application.php(380): yiiwebApplication->handleRequest(Object(apphejiangRequest)) #17 xxx/web/index.php(7): yiiaseApplication->run() #18 {main}
本地开发测试的时候好好的, 放到线上服务器 就出现问题. 把MySQL用户名, 密码都改成了线上的, 其他的都正常访问, 一遇到连接数据库的地方就会报上面的错误. 最终排查出问题原因: 吧线上服务器的localhost改成127.0.0.1就OK了,本地是可以使用localhost的,线上不行.