Bobcares

MariaDB Lost Connection During Query: Solution

by | Jul 28, 2022

 Let us go through the ‘connection to the MariaDB server lost’ and its solution in detail.

We can solve your MariaDB lost connection during query error at Bobcares with our Server Management Service.

Do you want to learn more? Continue reading and get in touch if you have any additional queries.

MariaDB lost connection

mariadb lost connection during query

This MariaDB lost connection during query issue frequently occurs when performing a long or sophisticated MySQL query that takes more than a few seconds to complete. Change the timeout-related global settings in the MySQL database server to resolve the error.

Increase the connection timeout from the command

When connecting to MySQL from the command line, use the —connect-timeout option to raise the number of seconds MySQL waits for a connection response. Increasing the timeout from the command can resolve the MariaDB lost connection during query error.

MySQL will wait 10 seconds before returning a connection timeout error by default. To wait for two minutes, the user can increase the number to 120 seconds:

mysql -uroot -proot --connect-timeout 120

The user can change the number 120 above to the amount of time they want to wait for a connection response. Once inside the MySQL console, a user may rerun the query to determine if it was successful.

The —connect-timeout option modifies the timeout seconds temporarily. It only works for the currently running MySQL session. Therefore the user must use the option each time they want the connection timeout extension. If the user wishes to make a permanent modification to the connection timeout variable, they must do so using their MySQL database server or the GUI interface used to access the database server.

First, let’s look at how to modify the timeout global variables in your MySQL database server to manage the MariaDB lost connection during query error.

Adjust the timeout global variables in your MySQL database server

The MySQL database holds timeout-related global variables, which a user can access by the following query:

SHOW VARIABLES LIKE "%timeout";

Here is the outcome from the local database. Change the following variables for MySQL to conduct longer queries:

Variable_name | Value |
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| have_statement_timeout | YES |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| mysqlx_connect_timeout | 30 |
| mysqlx_idle_worker_thread_timeout | 60 |
| mysqlx_interactive_timeout | 28800 |
| mysqlx_port_open_timeout | 0 |
| mysqlx_read_timeout | 30 |
| mysqlx_wait_timeout | 28800 |
| mysqlx_write_timeout | 60 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| replica_net_timeout | 60 |
| rpl_stop_replica_timeout | 31536000 |
| rpl_stop_slave_timeout | 31536000 |
| slave_net_timeout | 60 |
| wait_timeout | 28800

Use the SET GLOBAL query to update the variable values, as illustrated below.

SET GLOBAL connect_timeout = 600;

The query above should set the connect timeout variable to 600 seconds. The user can make changes to the numbers as they see suitable.

Adjust the timeout variables in your MySQL configuration files

Alternatively, if users want to alter the settings of the connections using a MySQL configuration file, they may edit the my.cnf (Mac) or my.ini (Windows) file used by the MySQL connection. Open the configuration file using the user’s preferred text editor, and they must identify the following variables in mysqld:

[mysqld]
connect_timeout = 10
net_read_timeout = 30
wait_timeout = 28800
interactive_timeout = 28800

The wait timeout and interactive timeout variables should not create any issues because their default value is 28800 seconds (or 8 hours). To avoid the ‘MariaDB lost connection during query error’, raise the connect timeout and net read timeout variable settings. Set it to at least 600 seconds (10 minutes).

Adjust timeout-related variables in your MySQL GUI tools

If the user is using GUI MySQL tools such as MySQL Workbench, Sequel Ace, or PHPMyAdmin, timeout-related variables.  Then the user can note its presence in the settings or preferences menu of these products.

Firstly the user must add my.cnf / my.ini in the [mysqld] section max_allowed_packet=32M. Based on the existing database, increase this value:

mysql -u user --password=password database name file_to_import

[Need assistance with similar queries? We are here to help]

Conclusion

To conclude, MariaDB lost connection during query indicates the loss of connection to the MariaDB server. And to fix the error modify the MySQL database server’s global timeout-related settings.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF