W
W
W1zer2017-09-05 12:31:49
Yii
W1zer, 2017-09-05 12:31:49

yii migrate does not work, gives an error SQLSTATE[HY000] [2002] how to overcome?

I am creating a new project in yii2 advanced. I open the console of the site directory, I did php init and then I write: php yii migrate
what gives me an error:

Yii Migration Tool (based on Yii v2.0.12)
Error: SQLSTATE[HY000] [2002] No such file or directory

or c127.0.0.1
Yii Migration Tool (based on Yii v2.0.12)
Error: SQLSTATE[HY000] [2002] Connection refused

I searched on the Internet how to solve this problem. I tried everything and replacing main-local.php localhostwith 127.0.0.1and writing to the console sudo killall mysql.does not help. Reinstalled MAMP (latest version), reinstalled MAC OS (sierra).
upd.
prescribed sudo php yii migrate
issues:
No log handling enabled - using stderr logging
Created directory: /var/db/net-snmp
Created directory: /var/db/net-snmp/mib_indexes
Yii Migration Tool (based on Yii v2.0.12)

Error: SQLSTATE[HY000] [2002] Connection refused

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-09-05
@W1zer

Give the database connection config, I think there is an error

M
Michael, 2018-12-19
@Zlocorp

Solution for MacOS 10.13 and MAMP/XAMPP (just change socket path).
You need to create a symlink to the MySQL socket so that PHP can see it. This solves the problem.
To do this, write in the console:

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question