Ab initio methods and density functional theory B3LYP with QCISD/6-311++G** basis set have been used to calculate the equilibrium geometries and vibrational properties of the possible structures and electronic states of MgB2 molecule. The present computational results predict that the ground electronic state is the triplet state 3B1 of C2v （B—Mg—B） with equilibrium geometry Re=2.2977，αBMgB=41.5521° and the energy of the ground state 3B1 is -248.9645 a.u.. Similarly, the harmonic frequency has been calculated. Then, the analytic potential energy function of MgB2 molecule is derived by many-body expansion theory for the first time. The contours of the potential energy surface are constructed, which clearly reproduce the character of the accurate equilibrium structure and dissociation energy for MgB2 molecule. Furthermore, the molecular static reaction pathway is investigated based on this potential energy function.