mac 使用 php artisan,在Mac php artisan上設置Laravel遷移錯誤:沒有這樣的文件或目錄[duplicate]...
This question already has an answer here:
這個問題已經有了答案:
Pulled a perfectly working laravel project from a git into a mac running MAMP. Project ran perfectly on a linux machine.
從一個git到一個運行MAMP的mac,從一個完美的工作的laravel項目。項目在linux機器上運行得很好。
composer install
作曲家安裝
php artisan migrate, got the following error:
php artisan遷移,得到以下錯誤: [PDOException]
SQLSTATE[HY000] [2002] No such file or directory
NB: php -v is 5.5 and mysql -v is 5.5 from the terminal Here is part of my config/database.php
NB: php -v是5.5,而mysql -v是5.5,這是我的config/database.php的一部分。
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'essays',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
I tried replacing localhost with 127.0.0.1 with no avail. Kindly help..
我嘗試用127.0.0.1替換localhost,但沒有用。請幫助. .
Edit: I added these three lines in my php.ini
編輯:我在ph .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
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
但這沒有解決。我還從git中提取了一個新的laravel項目,並在安裝了composer之后遇到了同樣的錯誤,然后php artisan才遷移
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
The mac version is 10.7.4
mac版是10.7.4
8 個解決方案
#1
168
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.
如果您正在使用MAMP,請確保添加具有mysql路徑值的unix_socket密鑰。襪子在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' => '',
),
#2
19
Do not assume your unix_socket which would be different from one to another, try to find it.
First of all, get your unix_socket location.
首先,獲取unix_socket位置。
$ mysql -uroot -p
Enter your mysql password and login your mysql server from command line.
輸入mysql密碼並從命令行登錄mysql服務器。
mysql> show variables like '%sock%';
+---------------+---------------------------------------+
| Variable_name | Value |
+---------------+---------------------------------------+
| socket | /opt/local/var/run/mysql5/mysqld.sock |
+---------------+---------------------------------------+
Your unix_soket could be diffrent.
你的unix_soket可能不同。
Then you got 2 solution to solve your issue:
然后你有兩個解決方案:
(1) Change your config/database.php
(1)改變你的配置/ database.php
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'essays',
'username' => 'root',
'password' => 'root',
'unix_socket' => '/opt/local/var/run/mysql5/mysqld.sock', //Your sock got from above
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
(2) Change your php.ini, find your php.ini file from
(2)改變你的php。ini,找到你的php。ini文件從
phpinfo();
You maybe install many php with different version, so please don't assume your php.ini file location, get it from your 'phpinfo';
您可能安裝了許多不同版本的php,所以請不要假設您的php。ini文件位置,從“phpinfo”獲取;
Change your php.ini:
改變你的php . ini中:
mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock
pdo_mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
Then restart your apache or php-fpm.
然后重新啟動apache或php-fpm。
#3
17
Had the same problem, but it's working for me now.
我也有同樣的問題,但現在對我有用。
If anybody is still having problems, try this:
如果有人仍然有問題,試試這個:
Make sure your bootstrap/start.php contains your actual hostname, not the name of your virtual host. Enter hostname in the terminal to get your hostname. As it's an array I believe you can enter both your hostname and the name(s) of your virtual host(s).
確保你的引導/啟動。php包含實際的主機名,而不是虛擬主機名。在終端中輸入主機名以獲取主機名。由於它是一個數組,我相信您可以輸入您的主機名和虛擬主機的名稱。
Replace "localhost" with "127.0.0.1".
用“127.0.0.1”代替“localhost”。
#4
12
If you are using XAMPP, the solution is:
如果您正在使用XAMPP,解決方案是:
'mysql' => array(
'driver' => 'mysql',
'unix_socket' => '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock',
'host' => 'localhost'
)
#5
9
This works for me in Laravel 5.0, change the DB_HOST=127.0.0.1:33060 in .env file.
這在Laravel 5.0中為我工作,在.env文件中更改DB_HOST=127.0.0.1:33060。
Others answers don't work...
其他答案不工作…
#6
5
For Laravel 5.0+ change localhost to 127.0.0.1 in your .env file as well before you go playing around with Unix Sockets etc - this worked for me.
對於Laravel 5.0+在您的.env文件中將localhost更改為127.0.0.1,然后再使用Unix套接字等等,這對我來說很有用。
Noobs beware: For anyone using Laravel 5 and using older learning material be aware that there was quite a marked shift in folder structure from previous versions though this seems to be for the better- check out this article https://mattstauffer.co/blog/laravel-5.0-directory-structure-and-namespace
Noobs注意:對於任何使用Laravel 5和使用較舊學習材料的人來說,請注意,文件夾結構與以前版本相比出現了明顯的變化,不過這似乎更好——請參閱本文https://mattstauff.co/blog/laravel-5.0 directorly - structure-namespace
#7
3
Another solution is to add the port number in the host key. In this case MAMP uses the 8889 by default:
另一種解決方案是在主機密鑰中添加端口號。在這種情況下,MAMP默認使用8889:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost:8889',
'database' => 'essays',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
#8
2
If you are using Laravle 5.1.11 version + MAC + MAMPP
如果您正在使用Laravle 5.1.11版本+ MAC + MAMPP
you have to add "Unix_socket " in file "yourapp"/app/config/database.php
您必須在文件“yourapp”/app/config/database.php中添加“Unix_socket”
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Unix_socket param was added to above mysql config drive.
Unix_socket param被添加到上面的mysql配置驅動中。
總結
以上是生活随笔為你收集整理的mac 使用 php artisan,在Mac php artisan上設置Laravel遷移錯誤:沒有這樣的文件或目錄[duplicate]...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 发票查验平台查询发票总显示系统繁忙的解决
- 下一篇: 腾讯视频回应多设备登录被封号:最多可在2