will83's avatar
Level 1

Failed job uses incorrect database login

My failed jobs driver seems to be using an incorrect database login and I cannot figure out how to change it. This issue seems to have started after I upgraded to Laravel 11 from Laravel 10, but I can't be sure if that is the cause.

The error I receive is as follows:

"Access denied for user 'xxx'@'localhost' (using password: YES) (Connection: mysql, SQL: insert into `failed_jobs` (`uuid`, `connection`, `queue`, `payload`, `exception`, `failed_at`)"

"xxx" is the database name and user of my staging environment. It is not referenced in any of the files in my production environment.

In my .env file, I define "DB_DATABASE" and "DB_USER" as "yyy". These are the correct settings. I have defined "DB_CONNECTION" as mysql. The failed_jobs table exists and has all the fields.

In config/queue, I have defined the failed driver as follows:

'failed' => [
        'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
        'database' => env('DB_CONNECTION', 'sqlite'),
        'table' => 'failed_jobs',
    ],

In config/database I have the default mysql configuration:

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DB_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'laravel'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => env('DB_CHARSET', 'utf8mb4'),
            'collation' => env('DB_COLLATION', 'utf8mb4_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'),
            ]) : [],

I have reset all cache using "php artisan cache:clear", I have restarted redis, and I have restarted the queues. Nothing seems to do the trick. Does anybody have any ideas?

0 likes
6 replies
tisuchi's avatar

@will83 Does your application have a proper connection with these env credentials?

IF SO, try this:

php artisan config:clear
php artisan cache:clear
php artisan queue:restart
php artisan config:cache
Snapey's avatar

did you restart the queue worker after making any changes?

will83's avatar
Level 1

Thank you for your suggestions.

@tisuchi - Yes my application connects to the correct database (yyy) just fine. It is reading and writing all application interactions without a problem. I followed your artisan commands. When I re-ran the job that has the queued jobs, I still get the same error.

@snapey - Yes, I restarted the queue.

I updated my supervisord job to specifically run in the "production" environment, and restarted supervisord and redis. Still no dice.

will83's avatar
Level 1

Restarting the queue does not help.

I found a supervisord job running on my staging environment and terminated that to avoid any possible conflict. That also has not helped.

Snapey's avatar

Whats in your .env file for these;

    'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
    'database' => env('DB_CONNECTION', 'sqlite'),

Please or to participate in this conversation.