Extensive two- and three-dimensional periodic first-principles simulations have been carried out to investigate the mechanical response of graphite to hydrostatic and nonhydrostatic stress conditions. Our results show a clear analogy between uniaxial $({\ensuremath{\sigma}}_{z})$ stress and hydrostatic pressure as far as structural changes in the unit cell are concerned. For intralayer C-C distances and in-plane graphite vibrational frequencies, the similarity with hydrostatic conditions is however found under biaxial $({\ensuremath{\sigma}}_{x}={\ensuremath{\sigma}}_{y})$ stresses. The calculated uniaxial equation of state is further used to investigate sliding mechanisms of a graphite layer in graphite at different interlayer separations, thus providing insight at an atomic level on the origin of the low static friction coefficient of graphite.