The moisture-induced instability of metal halide perovskites is one of the major challenges for perovskite devices. Although compositional engineering has been widely employed to improve the overall stability of perovskites, its effect on the moisture-induced instability received little attention. Here, we systematically study the interaction of water with the surfaces of primary perovskites, AMX3 (A+ = MA+, FA+, Cs+; M2+ = Pb2+, Sn2+; X− = I−, Br−), by using Density Functional Theory (DFT) calculations and comprehensive chemical bonding analysis. We reveal that the hydrophilic group NH3+ of MA+ cation may be the cause for instability issues. We find that the adsorption of water on FAPbI3 and CsPbI3 are much weaker than on MAPbI3 due to the less polarity of FA+ and Cs+. When exchanging M2+ cations, water adsorption on MASnI3 is also less energetically favorable than on MAPbI3 because of the weaker ionic interaction of H2O-MASnI3. When exchanging X− anion, water adsorption on MAPbBr3 is slightly weaker than on MAPbI3 due to the slightly weaker covalent interaction of H2O-MAPbBr3. Our results present a comprehensive understanding of the compositional effect on the interactions of water with perovskites and provide rational design strategies to improve their stability against moisture via compositional engineering.