The electronic structure of MgB2 with different lattice parameters, which represents the influence of pressure, has been studied from HF calculation. It has been found that the density of states at the Fermi level decreases with the decrease in lattice constant, which implies that the pressure can reduce the superconductivity of MgB2. It was also found that more electrons are introduced from the Mg layer to the B layer with increasing pressure, resulting in the number of holes on the B layer being reduced, thus reducing superconductivity. The electron density population at different pressures clearly shows that the triangle-shaped electron distribution in the B plane, extended along the B–B bonds, indicates the typical sp2 orbitals. On the other hand, there is no covalency feature between Mg and B atoms, indicating the ionic bonding property between Mg and B layers.