During upgrade system check: MySQL server has gone away

Environment:
php 5.6
max_execution_time 1448 secs
memory_limit 2048 MB
(I am aware that these settings are ridiculously large)

SuiteCRM: Version 7.10.1, Sugar Version 6.5.25 (Build 344)
Trigger of error message: Within the upgrade wizard, click on Next to execute the first step, the system check

Result: After about one minute, the function fails and displays two error messages

Error message 1:
Warning: mysqli_query(): MySQL server has gone away occurred in /home/somewhere/include/database/MysqliManager.php on line 136 [2018-03-22 11:37:07] display_stack_trace caller, file: /home/somewhere/include/utils.php line#: 3533
L:
/home/somewhere/include/database/MysqliManager.phpL:136
/home/somewhere/include/database/DBManager.phpL:3317
/home/somewhere/modules/UpgradeWizard/uw_utils.phpL:1393
/home/somewhere/modules/UpgradeWizard/systemCheck.phpL:138
/home/somewhere/modules/UpgradeWizard/index.phpL:297
/home/somewhere/include/MVC/View/SugarView.phpL:831
/home/somewhere/include/MVC/View/views/view.classic.phpL:74
/home/somewhere/include/MVC/View/SugarView.phpL:207
/home/somewhere/include/MVC/Controller/SugarController.phpL:432
/home/somewhere/include/MVC/Controller/SugarController.phpL:375
/home/somewhere/include/MVC/SugarApplication.phpL:109
/home/somewhere/index.phpL:52

Error message 2:
Warning: mysqli_query(): Error reading result set’s header occurred in /home/somewhere/include/database/MysqliManager.php on line 136 [2018-03-22 11:37:07] display_stack_trace caller, file: /home/somewhere/include/utils.php line#: 3533
L:
/home/somewhere/include/database/MysqliManager.phpL:136
/home/somewhere/include/database/DBManager.phpL:3317
/home/somewhere/modules/UpgradeWizard/uw_utils.phpL:1393
/home/somewhere/modules/UpgradeWizard/systemCheck.phpL:138
/home/somewhere/modules/UpgradeWizard/index.phpL:297
/home/somewhere/include/MVC/View/SugarView.phpL:831
/home/somewhere/include/MVC/View/views/view.classic.phpL:74
/home/somewhere/include/MVC/View/SugarView.phpL:207
/home/somewhere/include/MVC/Controller/SugarController.phpL:432
/home/somewhere/include/MVC/Controller/SugarController.phpL:375
/home/somewhere/include/MVC/SugarApplication.phpL:109
/home/somewhere/index.phpL:52

Impact: Upgrade cannot continue

Notes: Following the trace, the command upon which the sql is failing is apparently

query("CREATE TABLE temp (id varchar(36))");

If I execute that same command from within phpmyadmin, using the same connection credentials as SuiteCRM, it executes immediately. Note that there is no table “temp” before the upgrade is started.

I have performed numerous upgrades before and have never encountered such an error, neither during an upgrade nor anywhere else in SuiteCRM

I’ve seen this error coming up every once in a while, and it’s a serious error connecting PHP to the database. I never discovered exactly what is wrong, but often what people do is work around it.

The most obvious work-around for you would be to upgrade PHP to 7.0 or 7.1. This way you would get a ton of security and performance improvements, and you would effectively be using a new way to connect to your DB, probably circumventing your current problem.

Unfortunately not. Same error under php 7.1.
Is there a way to do an upgrade without having to use SuiteCRM’s gui interface?

There are silent installers, but not silent upgraders, no.

This is the line where it’s breaking:

https://github.com/salesagility/SuiteCRM/blob/v7.10.1/modules/UpgradeWizard/uw_utils.php#L1393

Maybe there’s something about your MySQL permissions that is lacking. Try GRANTing more permissions to your SuiteCRM database user, or using root. You will find you database user in config.php (which you configured when you installed)

No, as I mentioned before, while connecting with the same account I can create a temp table. In any case, that user has all the rights short of root. I cannot change it to root, being on a shared platform.
It seems to me if it were simply a matter of permissions, the command would return a very different sort of error message, no?

Sorry, I got lost jumping around so many threads and I didn’t recall your attemtps at creating temp table.

Yes, you are right that something is weird here, because the code is testing for permissions, but instead of getting an error back, MySQL loses control and “goes away”.

Maybe you can try simply commenting-out that line (skip the permissions test) and see if it breaks somewhere else, hopefully with a better error message…

EDIT: there is also a long list of possible cause here: https://dev.mysql.com/doc/refman/5.7/en/gone-away.html

So I commented out the offending check and then the same error occurred on the next permissions check.
I looked again at the permissions for the account in the database and confirmed that it has all permissions, albeit not the permission to grant those permissions.
I commented out all the db checks and the same error occurred:
/home/somewhere/include/database/MysqliManager.phpL:136
/home/somewhere/include/database/MysqlManager.phpL:281
/home/somewhere/include/database/DBManager.phpL:1650
/home/somewhere/include/database/MysqlManager.phpL:432
/home/somewhere/include/database/MysqlManager.phpL:1534
/home/somewhere/modules/UpgradeWizard/uw_utils.phpL:1128
/home/somewhere/modules/UpgradeWizard/systemCheck.phpL:163
/home/somewhere/modules/UpgradeWizard/index.phpL:297
/home/somewhere/include/MVC/View/SugarView.phpL:831
/home/somewhere/include/MVC/View/views/view.classic.phpL:74
/home/somewhere/include/MVC/View/SugarView.phpL:207
/home/somewhere/include/MVC/Controller/SugarController.phpL:432
/home/somewhere/include/MVC/Controller/SugarController.phpL:375
/home/somewhere/include/MVC/SugarApplication.phpL:109
/home/somewhere/index.phpL:52

Let me emphasize that I can view and update the objects in SuiteCRM, like leads, accounts, dropdown lists, etc.

Is it possible that the upgrade wizard is somehow trying to connect to the wrong database or use the wrong account? Where would this be defined? How can I debug that to see what is happening? (I am not at all a php developer.)

If I were you I would just go through that list on the MySQL site, one at a time. Every time I saw this error, it was eventually solved without any bug reported in SuiteCRM, it was just sysadmin problems.

Note that that list gives you specific things to check (like DNS resolution) that would never cross your mind unless they were written there…

By the way, is your database on the same server as your SuiteCRM? Are you connecting as localhost, 127.0.0.1, or what?

OK I’ll do that, but I have a feeling I shall have to come back to SuiteCRM to understand the issue.

No, the database is not on the same host as SuiteCRM. I doubt there is any issue communications between the two machines at the network level, because all other SUiteCRM functions work consistently whereas these upgrade tests fail consistently.