小編給大家分享一下Mysql中max_allowed_packet設(shè)定的示例分析,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
十余年建站經(jīng)驗, 網(wǎng)站設(shè)計制作、成都網(wǎng)站設(shè)計客戶的見證與正確選擇。創(chuàng)新互聯(lián)建站提供完善的營銷型網(wǎng)頁建站明細報價表。后期開發(fā)更加便捷高效,我們致力于追求更美、更快、更規(guī)范。max_allowed_packet是Mysql中的一個設(shè)定參數(shù),用于設(shè)定所接受的包的大小,根據(jù)情形不同,其缺省值可能是1M或者4M,比如是4M的情況下,這個值的大小即為:4 *1024*1024= 4194304
現(xiàn)象
當(dāng)日志中出現(xiàn)了諸如:“Package for query is too large (xxxxxxxx > 4194304). You can change this value on the server by setting the max_allowed_package variable”的提示的時候,錯誤的本身就清楚的提示了對應(yīng)的方式。
確認max_allowed_package
使用如下的方式可以確認當(dāng)前設(shè)定值
mysql> select @@max_allowed_packet; +----------------------+ | @@max_allowed_packet | +----------------------+ | 4194304 | +----------------------+ 1 row in set (0.00 sec) mysql>
或者
mysql> show variables like 'max_allowed_packet'; +--------------------+---------+ | Variable_name | Value | +--------------------+---------+ | max_allowed_packet | 4194304 | +--------------------+---------+ 1 row in set (0.00 sec) mysql>
修改
可以使用set命令來修改,但是只是臨時修改,重啟后即丟失。也可以直接修改過 mysql的設(shè)定文件并重啟mysql服務(wù),即可永久化保證設(shè)定。
根據(jù)mysql的安裝不同修改的文件也會有所不同,普通安裝方式可能會修改my.cnf,這里使用mysql的官方鏡像,其修改的文件應(yīng)該為:/etc/mysql/mysql.conf.d/mysqld.cnf
修改內(nèi)容:向此文件中添加如下設(shè)定
max_allowed_packet = 256M
修改前
[mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql #log-error = /var/log/mysql/error.log # By default we only accept connections from localhost #bind-address = 127.0.0.1 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0
修改后
[mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql #log-error = /var/log/mysql/error.log # By default we only accept connections from localhost #bind-address = 127.0.0.1 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 max_allowed_packet = 256M
重啟容器并確認
mysql> show variables like '%max_allowed_pack%'; +--------------------------+------------+ | Variable_name | Value | +--------------------------+------------+ | max_allowed_packet | 268435456 | | slave_max_allowed_packet | 1073741824 | +--------------------------+------------+ 2 rows in set (0.01 sec) mysql>
所以已經(jīng)看到已經(jīng)成功設(shè)定為256M(268435456)了
liumiaocn:~ liumiao$ echo "256*1024*1024" |bc 268435456 liumiaocn:~ liumiao$
看完了這篇文章,相信你對“Mysql中max_allowed_packet設(shè)定的示例分析”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!