The existence of a mass-metallicity (MZ) relation in star forming galaxies at all redshift has been recently established. We aim at studying some possible physical mechanisms contributing to the MZ relation by adopting analytical solutions of chemical evolution models including infall and outflow. We explore the hypotheses of a variable galactic wind rate, infall rate and yield per stellar generation (i.e. a variation in the IMF), as possible causes for the MZ relation. By means of analytical models we compute the expected O abundance for galaxies of a given total baryonic mass and gas mass.The stellar mass is derived observationally and the gas mass is derived by inverting the Kennicutt law of star formation, once the star formation rate is known. Then we test how the parameters describing the outflow, infall and IMF should vary to reproduce the MZ relation, and we exclude the cases where such a variation leads to unrealistic situations. We find that a galactic wind rate increasing with decreasing galactic mass or a variable IMF are both viable solutions for the MZ relation. A variable infall rate instead is not acceptable. It is difficult to disentangle among the outflow and IMF solutions only by considering the MZ relation, and other observational constraints should be taken into account to select a specific solution. For example, a variable efficiency of star formation increasing with galactic mass can also reproduce the MZ relation and explain the downsizing in star formation suggested for ellipticals. The best solution could be a variable efficiency of star formation coupled with galactic winds, which are indeed observed in low mass galaxies.