Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I've got a pretty basic question,

I am making a configuration script for mySQL replication between 2 new blank servers, now to make it a bit more failsafe I added the lines:

sed '/log-bin/d' /etc/my.cnf
sed '/server/d' /etc/my.cnf

So that, if there where already config options set by default, it would remove the lines in question.

Now, in the next step of the script I want it to readd those lines, with the options we desire. The only problem I'm having is that the my.cnf file is made up with

[mysqld]

like headers, what I'm wondering is (and can't find by means of google) is if these actually matter, of if they are mainly to indicate things.

can I just add

echo "log-bin=mysql-bin" >> /etc/my.cnf
echo "server-id=1" >> /etc/my.cnf

or do they need to be in the section marked with

[mysqld]

and if they are, can I "expand" the section by adding another

[mysqld]

at the bottom of the file so that you would have 2x this "region" ?

effectivly making it look like this:

#start file
[mysqld]
#options here
[mysql.server]
#options
[mysqld_safe]
#options
[mysqld]
log-bin=mysql-bin
server-id=1
share|improve this question

1 Answer 1

up vote 2 down vote accepted

Sure. Options in the group apply specially to that program. For example, [mysqld] apply to the mysqld server, [client] option group is read by all client programs, ...

About your question, sed can insert a line after finding the pattern, try this:

# sed '/\[mysqld\]/ a server-id=1' /etc/my.cnf
  • a command stands for append

It can be rewritten in 2 lines for more easier reading:

# sed '/\[mysqld\]/ a\
> server-id=1' /etc/my.cnf

You probably want to check if the server-id exist first:

# [ $(grep -c server-id /etc/my.cnf) -eq 0 ] && \
    sed '/^\[mysqld\]$/ a server-id=1' /etc/my.cnf
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.