PHP Artisan Migrate with MAMP and Unix Socket

一世执手 提交于 2019-12-02 19:45:51

Try this:

'mysql' => array(
'driver'    => 'mysql',
'unix_socket'   => getenv('UNIX_SOCKET'),
'host'      => getenv('DB_HOST'),
...
),

In .env add

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

though quite old question, but still can help others. so adding answer.

there is even simple solution. add this to ur .env file

DB_HOST=localhost;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock

In laravel 5.5 the unix_socket changes to DB_SOCKET

inside .env file :

DB_USERNAME=root
DB_PASSWORD=root
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

inside config/database.php:

    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),

Thanks, help fix migration issue for me using:

MAMP PRO 4.2
Laravel 5.5

inside .env file:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=<database name>
DB_USERNAME=<username - default root>
DB_PASSWORD=<password - default root>
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

inside config/database.php:

'connections' => [

    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', '<database name>'),
        'username' => env('DB_USERNAME', '<username - default root>'),
        'password' => env('DB_PASSWORD', '<password - default root>'),
        'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],
],

Also don't forget to add to app/Providers/AppServiceProviders.php:

use Illuminate\Support\Facades\Schema;
public function boot()
{
   Schema::defaultStringLength(191);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!