Mahesh
Mahesh

Reputation: 248

Why mysql max_allowed_packet reset to 1m automatically

I set

SET GLOBAL max_allowed_packet=16777216; 

and also

[mysqld]
max_allowed_packet = 16M

I checked the max_allowed_packet through below command

SHOW VARIABLES LIKE 'max_allowed_packet';

and the value is = 16777216

But after some days max_allowed_packet automatically reset to 1M.

Upvotes: 8

Views: 9802

Answers (6)

dpayne
dpayne

Reputation: 273

We just ran into this issue and the root cause is we were hacked. Some 3rd party was running a script that was changing the value down.

Tip for those trying to figure out if a hack is a root cause for them - temporarily change your MySQL logging to include all queries. That's how we ended up finding the issue.

Upvotes: 0

Mahesh
Mahesh

Reputation: 248

Yes, someone hack the system.I changed the root password and everything working fine.

Upvotes: 1

phiree
phiree

Reputation: 428

i am pretty sure that your are hacked. i had the same problem for months. i opened general_log and finally found some codes:

   connect root@someipaddress on
   Query select 0x4D5A900..........(verylong)
   Query select sys_exe('cmd /c  c:/windows/nbvqc4.vbs')
   .........
   set global max_allowed_packet 1024
   ........

suggestion: change your root password.

Upvotes: 6

Red Romanov
Red Romanov

Reputation: 474

Try setting 'Super' privilege of all users to 'N', except 1 admin user. This prevents users from changing max_allowed_packet.

Upvotes: 0

Trent Lloyd
Trent Lloyd

Reputation: 1892

MySQL has both GLOBAL variables and SESSION variables, as well as the my.cnf.

GLOBAL variables are initialised on startup from my.cnf, and many variables are taken from the GLOBAL value at connection time and copied into the SESSION. If you change the GLOBAL value, the SESSION keeps it's own value -- but any new sessions will take the new GLOBAL default.

It seems that you did the right thing in terms of setting the GLOBAL variable and updating my.cnf, but in your example you ran "SHOW VARIABLES" which returns the SESSION value. So it is possible you were not checking the correct value in that case. I would recommend for all future checks that you check both the global and session values to help get an idea of what is changing when.

SHOW GLOBAL VARIABLES LIKE 'max_allowed_packet'; SHOW SESSION VARIABLES LIKE 'max_allowed_packet';

For the value to change itself later, the following explanations are possible

(1) You are re-using a session that still has the old value (2) Another connection has run SET GLOBAL max_allowed_packet, it is possible even that some uncourteous application or script is doing this (3) The server was restarted, and the my.cnf change is not being applied as expected -- perhaps the file is in the wrong path, or the setting exists more than once in the configuration file. I would check the current Uptime in SHOW GLOBAL STATUS to understand if the server was restarted

I cannot think of any other reasons this would occur. I did check to see if the client negotiates the server-side value when you pass --max_allowed_packet but that does not seem to be the case.

Upvotes: 2

Santosh
Santosh

Reputation: 1815

By default value of max_allowed_packet is 1M in MySQL. I believe size of your "max_allowed_packet" is exceed its upper limit. So, when you check "SHOW VARIABLES LIKE 'max_allowed_packet';" its showing some negative value.

Additionally,

You have two values of max_allowed_packet in MySQL :

one on the client side : [mysql] section, [mysqldump], [client] and more. one on the server side : [mysqld] section.

Upvotes: 0

Related Questions