开发者

When using rails/activerecord to talk to a MySQL database, can I set max_allowed_packet?

MySQL has a setting called 'max_allowed_packet' which is set separately for clients and servers. On the server side it's in a config file, is it possible to set this to a non-default value on the client side when the client is rails ActiveRec开发者_StackOverflow中文版ord?


From the documnentation

On the client side, max_allowed_packet has a default of 1GB.

So, you just have to change it on the server side. Depending what version of MySQL you are using, you can do this on the fly on a global basis by running

SET GLOBAL max_allowed_packet=16777216

or

SET max_allowed_packet=16777216

where I assumed a 16MB max size. As you noted, you can also set the global variable in your my.cnf.

Currently, you cannot change this on a per-session basis.

mysql> SET SESSION max_allowed_packet=102400000; 

ERROR 1621 (HY000): SESSION variable 'max_allowed_packet' is read-only. Use SET GLOBAL to assign the value


I dont know if could help , but you can set mysql variable at runtime .

ActiveRecord::Base.connection.execute("set global max_allowed_packet=1000000000;")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜