[SOLVED]SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

This error showing in logging, just replaced username:

Doctrine\DBAL\Exception\DriverException: An exception occurred while executing ‘SELECT uid FROM oc_group_user WHERE (gid = ?) AND (uid = ?)’ with params [“username”, “username”]: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

There are quit a few (too many) topics on this, but haven’t found a solution, it seems Mysql runs out of memory and that there is not much one can do about that on a Raspberry Pi.
Haven’t been able to find out what triggers these errors. Cpu usage sky high (over or around 4.0) to a point of having to restart mysql server or reboot the pi.

NextCloudPi_09-27-17.img
Raspbian GNU/Linux 9 (stretch)"
Apache/2.4.25 (Raspbian)
PHP 7.0.19-1 (cli) (built: May 11 2017 14:04:47) ( NTS )
Zend Engine v3.0.0, php7.0-fpm
mysqld Ver 10.1.23-MariaDB-9+deb9u1 on armv7l

Edit to add another one:

Fatal cron An exception occurred while executing ‘UPDATE oc_jobs SET reserved_at = ‘0’ WHERE id = ?’ with params [“5”]: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

Same result CPU usage close to max, only rebooting brings things back to normal.

Did it run before? I had errors like this on corrupted sdcard/database. Try to check your sdcard and database for errors. System/Mounted sdcard can be checked also on reboot by touch /forcefsck and reboot. Database by mysqlcheck -u<rootuser> -p<rootpass> --all-databases
If database shows error, try dump and restore, also optimizing could help with -o as option for mysqlcheck command.

Just a try, as I remember this was my problem once.

Thanks for reply and tips, both fsck and mysqlcheck returned OK
Was running fine, I think, untill connected a 2.7TB external drive, I’ve removed it from NC and from fstab and NC has been up all morning without errors and CPU load average back to normal : 0.64, 0.37, 0.18

I had problems in the past with hight CPU using the ntfs-3g driver on an external USB HDD.

Maybe you are using NTFS?

No NTFS its ext4 (drive mounted on other Linux system now)
/dev/sdx1 256 732558335 732558080 2,7T 83 Linux

Last error was early this morning, just before I umount/remove drive

An exception occurred while executing ‘UPDATE oc_jobs SET reserved_at = ‘0’ WHERE id = ?’ with params [“5”]: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away 2017-10-24T07:14:56+0200