We present an ab initio molecular dynamics study of the alkali metal ions Li+, Na+, K+ and Cs+, and of the alkaline earth metal ions Mg2+ and Ca2+ in both pure water and electrolyte solutions containing the counterions Cl- and SO42-. Simulations were conducted using different density functional theory methods (PBE, BLYP and revPBE), with and without the inclusion of dispersion interactions (-D3). Analysis of the ion-water structure and interaction strength, water exchange between the first and second hydration shell, and hydrogen bond network and low-frequency reorientation dynamics around the metal ions have been used to characterise the influence of solution composition on the ionic solvation shell. Counterions affect the properties of the hydration shell not only when they are directly coordinated to the metal ion, but also when they are at the second coordination shell. Chloride ions reduce the sodium hydration shell and expand the calcium hydration shell by stabilizing under-coordinated hydrated Na(H2O)5+ complexes and over-coordinated Ca(H2O)72+. The same behaviour is observed in CaSO4(aq), where Ca2+ and SO42- form almost exclusively solvent-shared ion pairs. Water exchange between the first and second hydration shell around Ca2+ in CaSO4(aq) is drastically decelerated compared with the simulations of the hydrated metal ion (single Ca2+, no counterions). Velocity autocorrelation function analysis, used to probe the strength of the local ion-water interaction, shows a smoother decay of Mg2+ in MgCl2(aq), which is a clear indication of a looser inter-hexahedral vibration in the presence of chloride ions located in the second coordination shell of Mg2+. The hydrogen bond statistics and orientational dynamics in the ionic solvation shell show that the influence on the water-water network cannot only be ascribed to the specific cation-water interaction, but also to the subtle interplay between the level of hydration of the ions, and the interactions between ions, especially those of opposite charge. As many reactive processes involving solvated metal ions occur in environments that are far from pure water but rich in ions, this computational study shows how the solution composition can result in significant differences in behaviour and function of the ionic solvation shell.