We demonstrate and analyse a novel approach to enhance the threshold power of stimulated Brillouin scattering (SBS) in optical fibers, using a longitudinal compressive strain gradient. We derive analytical expressions for the power spectral density of the backscattered Stokes wave in the general case of passive and amplifying optical fibers, by considering the strain and optical power distributions. Our method provides an accurate prediction of the SBS gain spectrum, that we illustrate with a quantitative comparison between measurements and calculations of the SBS Stokes spectra, before and after applying the compression gradient. Our experimental results demonstrate the successful enhancement of the SBS threshold power by a factor of about 3 for the passive fiber and 2 for the amplifying fiber. The enhancement that we manage to calculate in the case of the passive fiber is in perfect agreement with the experimental result.