How can I replace the second character on a text file ...
...

and I need to replace the "B" character with "Z" obtaining something like this:

aZccccccc
dZccccccc

I tried :1,$s/B/Z/g in vi,
but that changed other "B" characters as well.

What else could I do?

Solution:

Your vi command will search from beginning of the line and replace
all "B"s by "Z"s - throughout the whole file.
Thats exactly what the g flag requests.
If you want to change only the second character
on each line, whatever character it is, try this:

:1,$g/\(.\)./s//\1Z/

This remembers the first character of each line
(\(.\))
and replaces the first two characters by the first character
(\1)
followed by a "Z".

If you want to replace the second character
only if it is "B", try this:

:1,$g/^\(.\)B/s//\1Z/

In the first example,
the search expression need not be anchored,
because any two characters will match.
In the second example,
the search
must
be anchored
(^),
otherwise the first "B" at any character position from column 2 on
will match.