I had a laravel 7 app I developed on my local (MAMP). I now want to set it up on my website hosting account (apache2, php7.4, mysql server). I did a git pull to pull down all the files and now when I do a
php artisan migrate
I get an error that says
SQLSTATE[HY000] [2002] No such file or directory (SQL: create table `migrations` (`id` int unsigned not null auto_increment primary key, `migration` varchar(191) not null, `batch` int not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
I am able to login to the phpmyadmin on the hosting server and see my empty database there.
My env file looks like this:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=commandcenterdb
DB_USERNAME=****
DB_PASSWORD=******
and my config/database.php file looks like this
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE',' commandcenterdb'),
'username' => env('DB_USERNAME', '*****'),
'password' => env('DB_PASSWORD', '********'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
2
Answers
I got the same error when using MAMP on a mac
I solved it by adding DB_SOCKET on
.env
fileif it doesn’t work try to modify the charset and collation on
config/database.php
fileits also worth to cross check ,i had UNIX_SOCKET instead of DB_SOCKET in the .env