A linear analysis of the ideal magnetohydrodynamic (MHD) stability of the Z-pinch is presented in which plasma flows are included in the equilibrium. Compressibility is introduced into MHD equations via the acoustic velocity of the plasma. It is found that, compressibility can stabilize the magneto-Rayleigh-Taylor/ Kelvin-Helmholtz (MRT/KH) instability, and this allows the sheared axial flow mitigate MRT instability far more effectively. Therefore, on the early stage of the implosion, because the temperature of the plasma is not high, the compressible model is much more suitable than the incompressible one. Different flow profiles have also been investigated, and it shows that the mitigation effect of the axial flow only depends on the magnitude of the velocity shear where the perturbations concentrate.