mysql max_allowed_packet查詢和修改

  • 目的:mysql根據配置文件會限制server接受的數據包大小。有時候大的插入和更新會被max_allowed_packet 參數限制掉,導致失敗。
  • 環境:ubuntu14.04

定義:
max_allowed_packet:server接受的數據包最大值

查看方法:
mysql> show VARIABLES like '%max_allowed_packet%';
顯示結果:
+--------------------+---------+
| Variable_name      | Value   |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+

以上說明目前的配置是:1M

修改方法:
  • 編輯mysql.cnf中的[mysqld]段,增加/修改爲:max_allowed_packet = 20M
  • 然後,重啓mysql服務,再次進行查看以確認是否設置生效。

p.s.這樣的修改方式不會因爲重啓服務而丟棄設置。

注意:

1.如果找不到mysql.cnf文件,可以在/etc/目錄下查找“mysql*.cnf":

linda@linda-pc:/etc$ find -name "mysql*.cnf"
find: `./docker': Permission denied
find: `./ssl/private': Permission denied
find: `./cups/ssl': Permission denied
find: `./polkit-1/localauthority': Permission denied
find: `./dovecot/private': Permission denied
./mysql/mysql.cnf
./mysql/conf.d/mysql.cnf
./mysql/mysql.conf.d/mysqld.cnf
2.重啓mysql服務:
linda@linda-pc:/etc/init.d$ sudo service mysql restart
* Stopping MySQL Community Server 5.7.18
.....
* MySQL Community Server 5.7.18 is stopped
* Re-starting MySQL Community Server 5.7.18
..
* MySQL Community Server 5.7.18 is started

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章