Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii error using migration tool

Tags:

php

yii

I'm trying to use the migration tool, but am getting the following error:

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...')

I have checked the DB settings in console.php, which are as follows:

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

As you can see, I've tried setting the host to 127.0.0.1 and setting the unix socket as per other suggestions.

I'm using MAMP (as you can see). from the protected dir, I'm running the command: ./yiic migrate

No matter what I change, I get the same error message.

*Update: *

I've just realized something. Changing the host=localhost to host=127.0.0.1 actually gives me a different error of connection refused. If I set that back to localhost the error is as follows:

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
like image 430
TH1981 Avatar asked Sep 12 '13 17:09

TH1981


2 Answers

You can check the yii framework forum, there is already similar question posted at http://www.yiiframework.com/forum/index.php/topic/16-db-connection-string

NOTE

Specifically, what solved it is this from that thread:

A note on PHP and Mac OSX: A version of PHP4 comes bundled on Mac OSX and is typically what is executed when you try the php command from the command line. You need to have the php command execute a version of PHP5.x or higher. Usually, you have already installed a version of PHP5.x or higher, but need to tell the php command to execute the newer version rather than the older one. There are certainly many ways to achieve this, but here is one:

At any terminal prompt, type in:

prompt>which php

this should tell you where the OS is looking for the php command tells me /usr/bin/php. If I navigate to /usr/bin and issue an ls *php* I will see three files:

php
php-config
phpize

These are all for the bundled version PHP4.x Rename these files to use a 4 in their names, to remember these are the executables for PHP4

mv php php4
mv php-config php-config4
mv phpize phpize4

Then, create sym links for each of these these to point to the PHP5.x or higher version you have installed. In my case these are located in /usr/local/apache/php/bin. So I would issue from the /usr/bin directory

ln -s [absolute path to your php5.x] php

and similarly for the other files.

like image 106
kachar Avatar answered Oct 21 '22 07:10

kachar


While running yyic I've got problems until I've changed localhost to 127.0.0.1 in the connection string.

like image 43
Aldekein Avatar answered Oct 21 '22 07:10

Aldekein