Various concentrations of Mg-doped ZnO nanorods (NRs) were prepared using co-precipitation technique. The objective of this study was to improve the photocatalytic properties of ZnO. The effect of Mg doping on the structure, phase constitution, functional groups presence, optical properties, elemental composition, surface morphology and microstructure of ZnO was evaluated with XRD, FTIR, UV–Vis spectrophotometer, EDS, and HR-TEM, respectively. Optical absorption spectra obtained from the prepared samples showed evidence of blueshift upon doping. XRD results revealed hexagonal wurtzite phase of nanocomposite with a gradual decrease in crystallite size with Mg addition. PL spectroscopy showed trapping efficiency and migration of charge carriers with electron–hole recombination behavior, while HR-TEM estimated interlayer d-spacing. The presence of chemical bonding, vibration modes and functional groups at the interface of ZnO was revealed by FTIR and Raman spectra. In this study, photocatalytic, sonocatalytic and sonophotocatalytic performance of prepared NRs was systematically investigated by degrading a mixture of methylene blue and ciprofloxacin (MBCF). Experimental results suggested that improved degradation performance was shown by Mg-doped ZnO NRs. We believe that the product synthesized in this study will prove to be a beneficial and promising photocatalyst for wastewater treatment. Conclusively, Mg-doped ZnO exhibited substantial (p < 0.05) efficacy against gram-negative (G-ve) as compared to gram-positive (G+ve) bacteria. In silico molecular docking studies of Mg-doped ZnO NRs against DHFR (binding score: − 7.518 kcal/mol), DHPS (binding score: − 6.973 kcal/mol) and FabH (− 6.548 kcal/mol) of E. coli predicted inhibition of given enzymes as possible mechanism behind their bactericidal activity.