Yii Error Using Migration Tool

I try to use the migration tool, but I get 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 checked the database settings in console.php , which look like this:

 '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 tried to set the host to 127.0.0.1 and install the unix socket according to other suggestions.

I am using MAMP (as you can see). from the protected directory I execute the command: ./yiic migrate

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

* Update: *

I just got it. Changing host=localhost to host=127.0.0.1 actually gives me another connection refused error. If I go back to localhost , the error will be the following:

 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 
+4
source share
11 answers

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

Note

In particular, that this was made from this thread:

Note on PHP and Mac OSX: The PHP4 version is shipped on Mac OSX and is usually executed when you try to run the php command from the command line. You need the php command to run version PHP5.x or higher. Usually you have installed version PHP5.x or higher, but you need to tell the php command to run a newer version, not an older one. Of course, there are many ways to achieve this, but here is one of them:

At any command prompt on the terminal, type:

 prompt>which php 

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

 php php-config phpize 

They all refer to the batch version of PHP4.x Rename these files to use 4 in their names to remember that these are executable files for PHP4

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

Then create sim links for each of them to indicate the version of PHP5.x or higher that you installed. In my case, they are located in /usr/local/apache/php/bin . So I would release from the directory /usr/bin

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

and similarly for other files.

+6
source

When starting yyic, I have problems until I change localhost to 127.0.0.1 in the connection string.

+2
source

Try specifying the port in the host line. Therefore localhost:8889 instead of localhost or 127.0.0.1 - depending on what you are using.

This fixed my problem.

+2
source

You can try setting unix_socket with the correct Socket keyword and just like the other vars in line with ; and without spaces:

 'connectionString' => 'mysql:host=localhost;dbname=yii_trackstar;Socket=/Applications/MAMP/tmp/mysql/mysql.sock', 

Here you can check additional connection strings: http://www.connectionstrings.com/mysql

+1
source

Try setting host = 127.0.0.1 to the db.php file

+1
source

A simple solution:

Just open & emsp; mail-local.php & emsp; page inside & emsp; backend / common / config & emsp; catalog.

Then change localhost to 127.0.0.1 .

Now you are running php yii migrate .

Hope it successfully creates tables in the Databse

+1
source

change the connection string to

 'connectionString' => 'mysql:host=localhost;dbname=yii_trackstar', 
0
source

Open a terminal and use this

 echo "export PATH=/Applications/MAMP/bin/php/php5.xx/bin:$PATH" >> ~/.profile 

5.xx is your version of PHP that you are using

This is because the Yii framework uses your default PHP with OSX, not with PHP MAMP. To verify this, enter "which php" to make sure it is / Applications / MAMP / bin / php / php 5.xx / bin / php, and you are done.

Hope this help :)

0
source

This is a problem with mac, which uses the old version of php installed on the computer, unlike php5, which comes with MAMP. So I had to force it to use PHP version 5, which comes with MAMP.

So I had to write this in Terminal, and it worked:

/Applications/MAMP/bin/php/php5.5.3/bin/php/Applications/MAMP/htdocs/projectname/protected/yiic migrate

0
source

Change the configuration of the /db.php file

 return [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=namedb', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', ]; 
0
source

MAMP PRO, click Enable Allow access to MySql in the Mysql menu.

0
source

Source: https://habr.com/ru/post/1501909/


All Articles