Consider this situation:
-- Server: max_allowed_packet = 200MB
-- Client: max_allowed_packet = 4MB
-- The following will return 200MB
SHOW variables like 'max_allowed_packet';
Without reading the configuration file, is it possible to determine the value of max_allowed_packet for the client? I’m using the MySQL C API.
Basically, I want my app to have something like:
max_allowed_packet = min(max_allowed_packet_server, max_allowed_packet_client)
You cannot directly determine
max_allowed_packetfor client at run time. When you executeshow variables like "max_allowed_packet", it shows max_allowed_packet for server side only and that too whatever it read at start time. And there seems no other way to find this value.Further, to solve your problem, by default, From MySQL Docs
Moreover, as you have specified that you are using
MySQL C API. You can set the value of max_allowed_packet, using mysql_options() API as follows:First create your option file with content
Lets say this file is saved as "c:/mysql.cnf" which sets the value for max_allowed_packet for client as 10MB. Now what you need is to include following line of code to read this file before your connect statement.
if you wish to change name of group from
clienttomyClientin file then, make your "c:/mysql.cnf" asand use following line of codes before your connection statement:
So, finally your code will look something like this:
Above line of code, will set your max_allowed_packet to 10M, now you can read server side max_allowed_packet using query "
show variables like "max_allowed_packet"" and you know your client side max_allowed_packet as 10MB.For further references 1
For MySQL Commandline client, MySQL docs says
Hope it helps, and serves your purpose….