Suddenly got
SQLSTATE[HY000]: General error: 1835 Malformed communication packet (SQL: select * from
tb_userswhere (username= 121211) limit 1)
on Laravel.
I already checked this: MySQL: ERROR 2027 (HY000): Malformed packet, but it seems a different case.
But my Laravel got the error I mentioned before. Any experience in this?
Found the solution. Don't know if it's permanent or temporary:
'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]**
],
make sure that
'options' => [PDO::ATTR_EMULATE_PREPARES => true]
exist on mysql connection.
Also ran into this issue after mariadb updated overnight. Downgrading mariadb fixed the issue for me.
All my Laravel apps running PHP 7.2 had this error but those running on PHP 7.3 did not. So I changed the PHP version to 7.3 and the problem was fixed. (Running Laravel 7)
After many workarounds i tried today this the solutions i got
1- upgrade to php 7.3 or 7.4
(many websites will be down after php upgrades )
2- downgrade to minor version ( mariadb 10.4.16 to 10.4.15)
yum downgrade MariaDB-server MariaDB-common MariaDB-shared MariaDB-client MariaDB-compat MariaDB-devel
anyway this problem is opened case as bug for Mariadb last night update and they didnt push any fixing for now the above solution is only the 2 ways to solve the problem , it works with me on mariadb downgrade from 10.4.16 to 10.4.15 (minor downgrade)
This issue started happening for a lot of people after the recent MariaDB update yesterday after Updating MariaDB to v10.3.26 (and 10.2.35). This issue is already addressed here: https://jira.mariadb.org/browse/MDEV-24121
As of now, these are the only known solutions:
1. Upgrade your PHP to 7.3: It appears these errors are shown on sites using php < 7.3. So upgrading your site's PHP to version 7.3 or 7.4 should resolve the issue.
CONS: Not a lot of applications can be easily upgraded to php 7.3 just like that. Sometimes you might need to update your platform, rewrite some codes or check all dependancies and see if they all work on 7.3. This may not be a quick fix for a lot of matured applications.
2. Downgrade MariaDB: This is a temporary fix since downgrading MariaDB will set it back to the previous state.
CONS: Downgrading MariaDB is not an easy thing to do with a click of a button from cpanel. You might need help from a network engineer to do the downgrade for you. After that you also might need to do yum-locking the MariaDB packages in order to avoid it from being updated until they're patched.
3. Add 'options' => [PDO::ATTR_EMULATE_PREPARES => true] to Database Config: This has been suggested in some answers which might solve 1 issue but open up a lot of other issues.
CONS: Adding the above to the database config file solved 1 problem for me, but it also opened a whole lot of other queries that were failing, database inserts where failing, etc. So I would not recommend this fix at all.
4. Wait for MariaDB Update: The next update should address this issue.
CONS: We don't know how long it will take to get an update that fixes this issue for older versions of PHP. It could be even days and some applications might not be able to wait that long.
So all in all, these are the only options I can see as of now. Just hoping there is a fix for it soon.
Short Term Fix: Out of all, downgrading MariaDB seems to be the only easy (sorta) temporary fix for me considering my application needs a lot of work to be ready for php 7.3. I downgraded MariaDB to 10.2.34 and locked it and the error no longer appears.
Long Term Fix: It is better to eventually get your application ready for php 7.3 and upgrade to that so MariaDB newer version also will not complain.
The official fix is finanlly out and you can find the details on the link:
https://support.cpanel.net/hc/en-us/articles/360056772334/comments/360005577354
To quickly fix it just connect via SSH and run
sudo /scripts/autorepair fix_mariadb_show_grants_roles
For users that have applied the previous workaround involving downgrading MariaDB. Be sure to unlock MariaDB to ensure it continues to receive the appropriate updates:
yum versionlock clear
/scripts/upcp
Upgrade php 7.2 to php7.4 best way for me.
` sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.4-fpm php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-soap php7.4-zip php7.4-bcmath -y
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php7.4-fpm
sudo systemctl reload apache2
sudo systemctl status php7.4-fpm `
Fixed
I'm on Ubuntu 20 (focal), note my repo you'll need to change it depending on if your on 16 (xenial), 18 (bionic) or whatever
I don't like the options fix in Laravel with the risk it could corrupt data, and I can't upgrade PHP to 7.2+ without a lot of work so for me I downgraded a version.
Going from 10.3.26 -> 10.3.25 without restoring all the data from a dump is not recommended but I had no choice, and it appears nothing bad happened.
# stop the database
service mariadb stop
# list packages installed
dpkg -l | grep mariadb
# remove whatever you have or the install will complain about dependencies or broken packages, you need to remove all the mariadb packages
apt remove mariadb-server-core-10.3
apt remove mariadb-server-10.3
apt remove mariadb-server-10.2
apt remove mariadb-server-10.1
# pin the repo to v10.3.25, remember to remove any conflicting sources you have in /etc/apt/sources.list
apt-get install software-properties-common
apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://archive.mariadb.org/mariadb-10.3.25/repo/ubuntu/ focal main'
# install the old version
apt install mariadb-server
# start it back up
service mariadb start
Updated php version**(7.2 to 7.3)** inside cpanel for my subdomain.
Must give all the previlege to the selected database user.
It worked for me.
What worked for me was to upgrade PHP version on the subdomain from 7.2 to 7.3. I did not change anything in the database configuration as has been suggested in some answers.
This sudden error message is caused by a MariaDB client upgrade, which appears to be incompatible with the PHP 7.2 version of php-mysqlnd; version 10.2.35 breaks it, but version 10.2.34 still works. With yum or dnf one can easily revert to the previous versions eg. with:
su
yum history
yum history undo 440
Temporary setting enabled=0 in /etc/yum.repo.d/mariadb.repo might also make sense.
Upgrading to PHP 7.3 might still be the better option (while available).
An emergency Release of MariaDB 10.5.8, 10.4.17, 10.3.27, and 10.2.36 is now available that was released to specifically solve this protocol incompatibility in old PHP versions and PDO.
MariaDB just released an upgrade that fixes the issue for those who cannot run their application on PHP >= 7.3, source: https://mariadb.org/mariadb-10-5-8-10-4-17-10-3-27-and-10-2-36-now-available/
Mariadb has a update for php 7.2 that fix this issue, just update the server:
sudo apt update
sudo apt upgrade
Easy Solution Just Update You PHP to 7.3 Work For me In Laravel & WP
This can happen if your query does not have the same number of input arguments as the array of argument you pass it in. Here is the code I had in NodeJS + MYSQL that was causing this issue:
const config = getMysqlConfig();
let arguments = [arg1, arg2];
const connection = await mysql.createConnection(config.db);
const result = await connection.execute('INSERT INTO mySchema.myTable(val1, val2) VALUES (?,?) ON DUPLICATE KEY UPDATE val1= val1+ ?', arguments)
.catch((err) => LogError(err));
connection.end();
Because I only had 2 values in arguments and yet my query was expecting 3 arguments, the malformed communication error was thrown. For me, the solution was just to add my addition argument in array
let arguments = [arg1, arg2, arg3];