Rbac in shell generates error message

Hi,

Following the book’s instructions in Chapter 8, I was able to open the Yii interactive tool and see Rbac in the list of available commands, but when I ran it, i got this error message, which I don’t understand and don’t know how to fix :( and I didn’t see this topic anywhere on the forum. I’m using MAMP on a Mac (this is my mysql path


/Applications/MAMP/Library/bin/mysql 

) . Something about database problem but I haven’t had any trouble connecting to mysql up to this point.

Anyone have an idea?


USAGE

  rbac


DESCRIPTION

  This command generates an initial RBAC authorization hierarchy.


>> rbac


Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Applications/MAMP/htdocs/framework/db/CDbConnection.php on line 389

exception 'CDbException' with message 'CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory' in /Applications/MAMP/htdocs/framework/db/CDbConnection.php:348

Stack trace:

#0 /Applications/MAMP/htdocs/framework/db/CDbConnection.php(297): CDbConnection->open()

#1 /Applications/MAMP/htdocs/framework/db/CDbConnection.php(275): CDbConnection->setActive(true)

#2 /Applications/MAMP/htdocs/framework/base/CModule.php(372): CDbConnection->init()

#3 /Applications/MAMP/htdocs/framework/web/auth/CDbAuthManager.php(540): CModule->getComponent('db')

#4 /Applications/MAMP/htdocs/framework/web/auth/CDbAuthManager.php(58): CDbAuthManager->getDbConnection()

#5 /Applications/MAMP/htdocs/framework/base/CModule.php(372): CDbAuthManager->init()

#6 /Applications/MAMP/htdocs/framework/base/CModule.php(86): CModule->getComponent('authManager')

#7 /Applications/MAMP/htdocs/demo/protected/commands/shell/RbacCommand.php(27): CModule->__get('authManager')

#8 /Applications/MAMP/htdocs/framework/cli/commands/ShellCommand.php(147): RbacCommand->run(Array)

#9 /Applications/MAMP/htdocs/framework/cli/commands/ShellCommand.php(99): ShellCommand->runShell()

#10 /Applications/MAMP/htdocs/framework/console/CConsoleCommandRunner.php(63): ShellCommand->run(Array)

#11 /Applications/MAMP/htdocs/framework/console/CConsoleApplication.php(88): CConsoleCommandRunner->run(Array)

#12 /Applications/MAMP/htdocs/framework/base/CApplication.php(155): CConsoleApplication->processRequest()

#13 /Applications/MAMP/htdocs/framework/yiic.php(33): CApplication->run()

#14 /Applications/MAMP/htdocs/demo/protected/yiic.php(7): require_once('/Applications/M...')

#15 /Applications/MAMP/htdocs/demo/protected/yiic(4): require_once('/Applications/M...')

#16 {main}



Can you try running


sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

from "Terminal" (found in ~/Applications/Utilities), and then trying again? You will need to type in your password.

If any errors appear, please post them here.

when I ran the statement you suggested in my terminal, it said


ln: /tmp/mysql.sock: File exists

I then started the Yii interactive tool and ran the same Rbac command, and got the same error message as in my OP.

Ok, how about if you do


sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

If you get an error saying /var/mysql doesn’t exist, then run


sudo mkdir /var/mysql

and then the code above again

I got this from running the statement in your last post


ln: /var/mysql/mysql.sock: File exists

and then when I ran Rbac in Yii interactive tool, I got same error message as in OP

Hmm, one more thing.

In your /protected/config/main.php file, where you have your ‘db’ settings array, try adding this to the end of the ‘connectionString’ property:


unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock

I’m not familiar with MAMP, so most of what I’m advising is coming from this thread:

http://www.yiiframework.com/forum/index.php?/topic/6554-database-connection-issue/page__p__33532&#entry33532

It’s also been suggested that changing ‘localhost’ to ‘127.0.0.1’ in you ‘connectionString’ may solve the problem.

There were a number of solutions posted on that site, but I just tried changing localhost to ‘127.0.0.1’ and it worked. Thanks

If your using MAMP, then you might need to add he port number to the connection string.

eg

‘connectionString’ => ‘mysql:host=localhost;port=8889;dbname=testdrive’,