8

Good morning. I'm using Laravel on VPS server.

Short situation description: Yesterday everything was working fine (for months our website were working fine), this morning I got woke up from my colleagues that both of our websites are down.

When trying to access them we receive error:

SQLSTATE[HY000]: General error: 1835 Malformed communication packet (SQL: select * from users where id = 1 limit 1)

I have checked online and can't find a solution. I tried to upgrade MySQL to newest version (Maria DB 10.3)

I tried to reset password for database user. (Also no changes)

I checked and tried sollution to set read_rnd_buffer_size=256K in my.cnf file for mysql settings

When I try to call this function directly in phpMyAdmin select * from users where id = 1 limit 1 it returns expected results.

I will appreciate every help, as all of our business depends on these platforms, I need to make them work as soon as possible.

With greetings, Artis.

Edit: When I try to disable function that causes error, it just shows next function, and all over like that. So I believe that Laravel can't conect with mysql at all.

After deeper research I found out that only Laravel can't connect to database. On same server I have 2x Laravel applications, Codeigniter and wordpress. Both Laravel applications stopped to work at same time, but codeigniter and wordpress works as expected.

Crelix
  • 349
  • 1
  • 12
  • Are you using MariaDB? – Repox Nov 04 '20 at 11:19
  • Yes. I believe so. – Crelix Nov 04 '20 at 11:36
  • 1
    Happened to several people today (https://stackoverflow.com/questions/64677005/general-error-1835-malformed-communication-packet). See https://stackoverflow.com/questions/64677836/sqlstatehy000-general-error-1835-malformed-communication-packet-on-laravel for solution (or maybe just workaround). – Smuuf Nov 04 '20 at 11:50
  • 1
    @Smuuf Thank you, I will check them out right now. :) – Crelix Nov 04 '20 at 11:51
  • 1
    @Smuuf Thank you, You are a life saver. :) Before when I checked I didn't see these topics. If you put it as answer, I will approve it. :) – Crelix Nov 04 '20 at 11:58
  • Does this answer your question? [SQLSTATE\[HY000\]: General error: 1835 Malformed communication packet on LARAVEL](https://stackoverflow.com/questions/64677836/sqlstatehy000-general-error-1835-malformed-communication-packet-on-laravel) – Peter O. Nov 08 '20 at 09:54

2 Answers2

9

for a quick fix just add this

'options' => [PDO::ATTR_EMULATE_PREPARES => true]

to config/database.php in

'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', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => null,
        'options'   => [PDO::ATTR_EMULATE_PREPARES => true],
    ],

the proper solution is to upgrade your php from 7.2 to 7.4 or downgrade your mariadb

aitbella
  • 958
  • 9
  • 19
  • Thanks @aitbella. It's a bug introduced on the latest version of MariaDB: [MDEV-24121](https://jira.mariadb.org/browse/MDEV-24121) – AlexWebLab Nov 05 '20 at 02:38
  • This actually worked for me. I tried upgrading php version to 7.3 but didn't work, don't know why. For now using this fix. Thank you. – Subash Bhattarai Nov 10 '20 at 14:10
  • Unfortunately, upgrading php to 7.4 still didn't work for me @aitbella. Tried 7.3, 7.3 Native and 7.4, but neither of them worked. Using the quick fix mentioned at least for now. – Subash Bhattarai Nov 12 '20 at 06:06
1

The new update requires PHP 7.3 to connect with MariaDB.

Since the issue is caused by the latest upgrade from MariaDB MDEV-24121, a more suitable solution is to downgrade MariaDB and yum-locking the MariaDB packages in place to avoid the packages from being updated and unlock them when they're patched. More details here on how to do it: Updating MariaDB to v10.2.35 or v10.3.26, causes MySQL Databases interface to show MySQL as offline

If you cannot downgrade your MariaDB or cannot update your PHP, a possible workaround is to set "PDO::ATTR_EMULATE_PREPARES" to true.

AlexWebLab
  • 846
  • 3
  • 15
  • 29