我正在尝试使用迁移工具,但出现以下错误:
exception 'CDbException' with message 'CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Connection refused' in /Applications/MAMP/htdocs/yii-sandbox/framework/db/CDbConnection.php:382
Stack trace:
#0 /Applications/MAMP/htdocs/yii-sandbox/framework/db/CDbConnection.php(330): CDbConnection->open()
#1 /Applications/MAMP/htdocs/yii-sandbox/framework/db/CDbConnection.php(308): CDbConnection->setActive(true)
#2 /Applications/MAMP/htdocs/yii-sandbox/framework/base/CModule.php(387): CDbConnection->init()
#3 /Applications/MAMP/htdocs/yii-sandbox/framework/cli/commands/MigrateCommand.php(442): CModule->getComponent('db')
#4 /Applications/MAMP/htdocs/yii-sandbox/framework/cli/commands/MigrateCommand.php(451): MigrateCommand->getDbConnection()
#5 /Applications/MAMP/htdocs/yii-sandbox/framework/cli/commands/MigrateCommand.php(482): MigrateCommand->getMigrationHistory(-1)
#6 /Applications/MAMP/htdocs/yii-sandbox/framework/cli/commands/MigrateCommand.php(84): MigrateCommand->getNewMigrations()
#7 [internal function]: MigrateCommand->actionUp(Array)
#8 /Applications/MAMP/htdocs/yii-sandbox/framework/console/CConsoleCommand.php(172): ReflectionMethod->invokeArgs(Object(MigrateCommand), Array)
#9 /Applications/MAMP/htdocs/yii-sandbox/framework/console/CConsoleCommandRunner.php(71): CConsoleCommand->run(Array)
#10 /Applications/MAMP/htdocs/yii-sandbox/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run(Array)
#11 /Applications/MAMP/htdocs/yii-sandbox/framework/base/CApplication.php(180): CConsoleApplication->processRequest()
#12 /Applications/MAMP/htdocs/yii-sandbox/framework/yiic.php(33): CApplication->run()
#13 /Applications/MAMP/htdocs/yii-sandbox/projects/trackstar/protected/yiic.php(7): require_once('/Applications/M...')
#14 /Applications/MAMP/htdocs/yii-sandbox/projects/trackstar/protected/yiic(4): require_once('/Applications/M...')
我检查了 中的数据库设置console.php
,如下所示:
'db'=>array(
'connectionString' => 'mysql:host=127.0.0.1;dbname=yii_trackstar, unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock',
'emulatePrepare' => true,
'username' => 'yii',
'password' => 'xxx',
'charset' => 'utf8',
),
如您所见,我尝试将主机设置为 127.0.0.1 并按照其他建议设置 unix 套接字。
我正在使用 MAMP(如您所见)。从受保护的目录中,我正在运行命令:./yiic migrate
无论我更改什么,我都会收到相同的错误消息。
*更新:*
我刚刚意识到一件事。更改host=localhost
为host=127.0.0.1
实际上给了我一个不同的错误connection refused
。如果我将其设置回localhost
错误如下:
exception 'CDbException' with message 'CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory' in /Applications/MAMP/htdocs/yii-sandbox/framework/db/CDbConnection.php:382