cakephp bake SQLSTATE[HY000] [2002] 没有这样的文件或目录
Posted
技术标签:
【中文标题】cakephp bake SQLSTATE[HY000] [2002] 没有这样的文件或目录【英文标题】:cakephp bake SQLSTATE[HY000] [2002] No such file or directory 【发布时间】:2019-05-08 02:32:49 【问题描述】:我遵循 Cakephp 教程,到目前为止一切正常(新添加的文章显示在数据库中)。但是现在我尝试“bin/cake bake model users”我收到以下错误消息: SQLSTATE[HY000] [2002] No such file or directory in [/opt/lampp/htdocs/MyApp/vendor/cakephp/cakephp/ src/Database/Driver.php,第 92 行]。 我在这里找到了这个解决方案:SQLSTATE HY000 2002 while running bake command。但这似乎不适用于linux(Ubuntu)。任何帮助将不胜感激。
完全错误:
Exception: SQLSTATE[HY000] [2002] No such file or directory in [/opt/lampp/htdocs/MyApp/vendor/cakephp/cakephp/src/Database/Driver.php, line 92] 2018-12-06 11:28:03 Error: [PDOException] SQLSTATE[HY000] [2002] No such file or directory in /opt/lampp/htdocs/MyApp/vendor/cakephp/cakephp/src/Database/Driver.php on line 92 Stack Trace:
#0 /opt/lampp/htdocs/MyApp/vendor/cakephp/cakephp/src/Database/Driver.php(92): PDO->__construct('mysql:host=loca...', 'root', '', Array)
#1 /opt/lampp/htdocs/MyApp/vendor/cakephp/cakephp/src/Database/Driver/Mysql.php(106): Cake\Database\Driver->_connect('mysql:host=loca...', Array)
#2 /opt/lampp/htdocs/MyApp/vendor/cakephp/cakephp/src/Database/Schema/BaseSchema.php(45): Cake\Database\Driver\Mysql->connect()
#3 /opt/lampp/htdocs/MyApp/vendor/cakephp/cakephp/src/Database/Dialect/MysqlDialectTrait.php(63): Cake\Database\Schema\BaseSchema->__construct(Object(Cake\Database\Driver\Mysql))
#4 /opt/lampp/htdocs/MyApp/vendor/cakephp/cakephp/src/Database/Schema/Collection.php(52): Cake\Database\Driver\Mysql->schemaDialect()
#5 /opt/lampp/htdocs/MyApp/vendor/cakephp/cakephp/src/Database/Schema/CachedCollection.php(42): Cake\Database\Schema\Collection->__construct(Object(Cake\Database\Connection))
#6 /opt/lampp/htdocs/MyApp/vendor/cakephp/cakephp/src/Database/Connection.php(391): Cake\Database\Schema\CachedCollection->__construct(Object(Cake\Database\Connection), true)
#7 /opt/lampp/htdocs/MyApp/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(1052): Cake\Database\Connection->getSchemaCollection()
#8 /opt/lampp/htdocs/MyApp/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(1006): Bake\Shell\Task\ModelTask->_getAllTables()
#9 /opt/lampp/htdocs/MyApp/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(213): Bake\Shell\Task\ModelTask->listAll()
#10 /opt/lampp/htdocs/MyApp/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(131): Bake\Shell\Task\ModelTask->getAssociations(Object(Cake\ORM\Table))
#11 /opt/lampp/htdocs/MyApp/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(114): Bake\Shell\Task\ModelTask->getTableContext(Object(Cake\ORM\Table), 'users', 'Users')
#12 /opt/lampp/htdocs/MyApp/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(101): Bake\Shell\Task\ModelTask->bake('Users')
#13 /opt/lampp/htdocs/MyApp/vendor/cakephp/cakephp/src/Console/Shell.php(532): Bake\Shell\Task\ModelTask->main('users')
#14 /opt/lampp/htdocs/MyApp/vendor/cakephp/cakephp/src/Console/Shell.php(525): Cake\Console\Shell->runCommand(Array, false, Array)
#15 /opt/lampp/htdocs/MyApp/vendor/cakephp/cakephp/src/Console/CommandRunner.php(342): Cake\Console\Shell->runCommand(Array, true)
#16 /opt/lampp/htdocs/MyApp/vendor/cakephp/cakephp/src/Console/CommandRunner.php(164): Cake\Console\CommandRunner->runShell(Object(Bake\Shell\BakeShell), Array)
#17 /opt/lampp/htdocs/MyApp/bin/cake.php(12): Cake\Console\CommandRunner->run(
数组)
18 主要
【问题讨论】:
你用 composer 安装 Cakephp 了吗? 看来如果您删除vendor
目录并执行composer install
问题将得到解决
我刚刚遇到了同样的问题,Linux 上的 Xampp 堆栈中的 CakePHP 3.8。原因是运行的 PHP 版本错误(我在系统范围内安装的 PHP 在/usr/bin/php
)。解决方案:将路径 /opt/lampp/bin
添加到我的 PATH 中,一切都很好。 :)
【参考方案1】:
遵循以下几点
-
您的 cake-php 未连接到任何本地数据库,请访问
pagesController 从浏览器查看它是否连接到数据库,如果
不需要在 config/app.php 中配置数据库名称和
凭据。
你在 cake-php 项目目录下,尝试点击相同的“bin\cake
烘焙模型用户”在 Windows 中,对于 linux 使用“bin/cake bake model
用户”。
如果问题未解决,请回复此主题
【讨论】:
【参考方案2】:在我的情况下,通过更改 app/config.php 解决了问题,只需将数据源主机从“localhost”更改为“127.0.0.1”
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => '127.0.0.1',...
【讨论】:
以上是关于cakephp bake SQLSTATE[HY000] [2002] 没有这样的文件或目录的主要内容,如果未能解决你的问题,请参考以下文章
CakePHP - 调用另一个模型导致“SQLSTATE [42000]:语法错误或访问冲突”
Cakephp SQLSTATE [42000]:语法错误或访问冲突:1064
为啥 CakePHP 无法为一个控制器创建夹具并返回 SQLSTATE[42000] 而它是为另一个控制器?
laravel SQLSTATE[HY000] [2002] 没有这样的文件或目录 (SQL: select * from `sessions` where `id` =