0
votes

I am learning php and I can’t deal with database migration. I use MAMP, Apache web server, php 7.4.12. Apache port-8888 mysql port 8889 set web & mysql ports to MAMp deaful 80 & 3306 Many errors occur when I perform migrations. For example:

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = php_laravel and table_name = migrations and table_type = 'BASE TABLE')

my database.php

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

my .env

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:zxW5bfOMFQrYaH/kTOriBZV+SLzacHvbNAtBKRkmx0A=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=php_laravel
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

Brothers, help. I tried everything I knew. Changed ports, wrote prefixes, changed names and passwords, nothing helped. Help me please.

1
Try connecting to your database manually first, using a MySQL client. Find out which port it is really running on. Find out what user and password connect to it. Then plug those details into your connection information. The error is quite explicit - it can't connect to the database server - so find out why first. Also, you are connecting as root and I hope you have deleted the password from the configs you posted here. You will need a password in the real world. Also, consider creating a database user that isn't root to use. - Skrrp

1 Answers

0
votes

It was necessary to add a line to the socket 'unix_socket' => env ('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),