jmrufus's avatar

SQLSTATE[HY000] [2002] Connection refused table sessions

Hi guys.

I'm a little desperate with this issue. I've deployed a project to production.

I created the DBase and imported SQL with tables and corresponding data.

However, when I try to access the site, it shows me the following error:

SQLSTATE[HY000] [2002] Connection refused (Connection: mysql, SQL: select * from sessions where id = M4Uh039sUChdeOHtHM1vDnf4lEN2lY2Zk9e5oBTq limit 1)

I've checked the database connection information and it's correct. The sessions table exists, but I don't understand why it's throwing this error.

Has anyone had this problem and knows how to fix it?

Thanks in advance.

Best regards.

0 likes
13 replies
Tray2's avatar

Make sure that you have the right credentials in your .env file, and the correct database name and server.

2 likes
jmrufus's avatar

Hello,

This is a Laravel/Filament project that I updated from version 11.33 to 11.44.

Everything works fine locally.

When I upload everything to production, the .ENV file is still the same as it was in the unupgraded version, as is the DBase, but I'm still getting the error with the sessions table.

I don't understand why this happens; only the version upgrade files have been changed.

Any ideas?

Thanks for the help.

Best regards.

1 like
Tray2's avatar

@jmrufus Is the mysql server still running? Try restarting it,

2 likes
jmrufus's avatar

The MySQL server is running and is not experiencing any issues, as I have other applications running and they don't display this error.

I can't restart the server because it's a shared hosting.

1 like
vincent15000's avatar

@jmrufus Does the application access the other tables or is the problem only with the sessions table ?

1 like
jmrufus's avatar

I can't access anything. I get the error just by accessing the main page.

That's why I think it must be something it's saving somehow, since in theory it's not accessing the database, since it doesn't even give me the option to log in.

Best regards.

1 like
michaelyousrie's avatar

@jmrufus Try to use tinker to check if the application has access to the DB outside the sessions table.

php artisan tinker
// Assuming you still have the default user model.

App\Models\User::first();

If the above doesn't throw any errors, then make sure the sessions table exist and is accessible.


If it doesn't work, which most likely it won't, then it HAS to be a .env issue as, most likely, your application is not loading the .env file (assuming that you have a .env file and it has the correct DB credentials in it).

As something to try, you can clear the config cache from your application to eliminate that possibility.

php artisan config:clear

--

2 likes
michaelyousrie's avatar

I can see that you're using a shared hosting from your comments here.

I remember having a problem once with shared hosting providers where my .env file wasn't being considered and I had to manually set the environment variables on the hosting level instead of the .env file.

I hope this puts you on the right path.

2 likes
jlrdw's avatar

Can you connect with phpmyadmin?

1 like
Snapey's avatar

if you are manually (FTP) uploading the site to the server then you may well be copying over the cache of your local config.

You need to run artisan config:clear on the production server, or run config:clear before you upload the files.

If you have command line access, run the artisan config commands to check the database config values.

2 likes
vincent15000's avatar

Have you checked if the application doesn't try to access another database where you don't have any table migrated into ?

I had such a problem last month, it was due to a .env.local environment file that looked for another database than the one declared inside the .env file.

You should check the configuration in production.

2 likes
ajinaniyan's avatar

That SQLSTATE[HY000] [2002] Connection refused error usually means Laravel can’t reach your MySQL server not that the sessions table itself is broken. It’s common after updates or on shared hosts.

Try this:

In your .env, set DB_HOST=127.0.0.1 (not localhost) and recheck the username/password.

Run:

php artisan config:clear php artisan cache:clear

Some hosts use a different socket, like /tmp/mysql.sock, so you might need:

DB_SOCKET=/tmp/mysql.sock

Make sure your .env file is actually being loaded — some shared hosts ignore it.

If the issue persists, your MySQL instance might’ve gotten corrupted or disconnected. Running a quick repair using a tool like Stellar Repair for MySQL can help restore stability before reconnecting Laravel.

2 likes
JussiMannisto's avatar

This is an ad bot. Every message ends with them advertising their product.

1 like

Please or to participate in this conversation.