在 Mac 上设置 Laravel php artisan migrate 错误:没有这样的文件或目录 [英] Setting up Laravel on a Mac php artisan migrate error: No such file or directory
问题描述
- 将一个完美运行的 laravel 项目从 git 拉入运行 MAMP 的 mac.项目在 linux 机器上完美运行.
- 作曲家安装
php artisan migrate,出现以下错误:
- Pulled a perfectly working laravel project from a git into a mac running MAMP. Project ran perfectly on a linux machine.
- composer install
php artisan migrate, got the following error:
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
注意:php -v 是 5.5 和 mysql -v 是 5.5 从终端这是我的 config/database.php 的一部分
NB: php -v is 5.5 and mysql -v is 5.5 from the terminal Here is part of my config/database.php
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'essays',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
我尝试用 127.0.0.1 替换 localhost,但无济于事.请帮忙..
I tried replacing localhost with 127.0.0.1 with no avail. Kindly help..
我在我的 php.ini 中添加了这三行
I added these three lines in my php.ini
mysql.default_socket = /var/run/mysqld/mysqld.sock
mysqli.default_socket = /var/run/mysqld/mysqld.sock
pdo_mysql.default_socket = /var/run/mysqld/mysqld.sock
我还添加了这个符号链接:
I also added this symlink:
sudo mkdir /var/mysql
cd /var/mysql && sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
但这并没有解决.我还从 git 中提取了一个全新的 Laravel 项目,并在 composer install
然后 php artisan migrate
But that didnt solve. I also pulled a fresh new laravel project from git and ran into the same error after composer install
then php artisan migrate
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
mac 版本为 10.7.4
The mac version is 10.7.4
推荐答案
如果您使用的是 MAMP,请务必添加 unix_socket
键和 mysql.sock 的路径值
驻留在 MAMP 中.
If you are using MAMP be sure to add the unix_socket
key with a value of the path that the mysql.sock
resides in MAMP.
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'database' => 'database',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
这篇关于在 Mac 上设置 Laravel php artisan migrate 错误:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!