Home Ask Login Register

Developers Planet

Your answer is one click away!

Alwin Kesler February 2016

Add max_allowed_packet to my.cnf in vagrant environment

So I have a box that includes a mysqldump file executed at provision. The problem now is that I need to increase the max_allowed_packet variable before execute this script.

How can I do something like:

max_allowed_packet = 128M >> /etc/my.cnf

but rather than at the EOF do it after the [mysqld] section

Thank you


Cyrus February 2016

With GNU sed:

sed -i 's|\[mysqld\]|&\nmax_allowed_packet = 128M|' /etc/my.cnf

-i: edit file "in place"

&: refer to that portion which matched

\n: new line

Alwin Kesler February 2016

Thanks to @Cyrus

sed -i.bak 's|[mysqld]|&\nmax_allowed_packet = 128M|' /etc/my.cnf

Post Status

Asked in February 2016
Viewed 3,573 times
Voted 6
Answered 2 times


Leave an answer

Quote of the day: live life