Context. Global magnetohydrodynamic simulations show the growth of Kelvin-Helmholtz instabilities at the contact surface of two merging neutron stars. That region has been identified as the site of efficient amplification of magnetic fields. However, these global simulations, due to numerical limitations, were unable to determine the saturation level of the field strength, and thus the possible back-reaction of the magnetic field onto the flow. Aims. We investigate the amplification of initially weak magnetic fields in Kelvin-Helmholtz unstable shear flows, and the backreaction of the field onto the flow. Methods. We use a high-resolution finite-volume ideal MHD code to perform 2D and 3D local simulations of hydromagnetic shear flows, both for idealized systems and simplified models of merger flows. Results. In 2D, the magnetic field is amplified on time scales of less than 0.01 ms until it reaches locally equipartition with the kinetic energy. Subsequently, it saturates due to resistive instabilities that disrupt the Kelvin-Helmholtz unstable vortex and decelerate the shear flow on a secular time scale. We determine scaling laws of the field amplification with the initial field strength and the grid resolution. In 3D, the hydromagnetic mechanism seen in 2D may be dominated by purely hydrodynamic instabilities leading to less filed amplification. We find maximum magnetic fields ∼10 16 G locally, and rms maxima within the box ∼10 15 G. However, due to the fast decay of the shear flow such strong fields exist only for a short period (<0.1 ms). In the saturated state of most models, the magnetic field is mainly oriented parallel to the shear flow for rather strong initial fields, while weaker initial fields tend to lead to a more balanced distribution of the field energy among the components. In all models the flow shows small-scale features. The magnetic field is at most in energetic equipartition with the decaying shear flow. Conclusions. The magnetic field may be amplified efficiently to very high field strengths, the maximum field energy reaching values of the order of the kinetic energy associated with the velocity components transverse to the interface between the two neutron stars. However, the dynamic impact of the field onto the flow is limited to the shear layer, and it may not be adequate to produce outflows, because the time during which the magnetic field stays close to its maximum value is short compared to the time scale for launching an outflow (i.e., a few milliseconds).