Aims: With this paper we want to investigate the highly variable afterglow light curve and environment of gamma-ray burst (GRB) 060526 at $z=3.221$. Methods: We present one of the largest photometric datasets ever obtained for a GRB afterglow, consisting of multi-color photometric data from the ultraviolet to the near infrared. The data set contains 412 data points in total to which we add additional data from the literature. Furthermore, we present low-resolution high signal-to-noise spectra of the afterglow. The afterglow light curve is modeled with both an analytical model using broken power law fits and with a broad-band numerical model which includes energy injections. The absorption lines detected in the spectra are used to derive column densities using a multi-ion single-component curve-of-growth analysis from which we derive the metallicity of the host of GRB 060526. Results: The temporal behaviour of the afterglow follows a double broken power law with breaks at $t=0.090pm0.005$ and $t=2.401pm0.061$ days. It shows deviations from the smooth set of power laws that can be modeled by additional energy injections from the central engine, although some significant microvariability remains. The broadband spectral-energy distribution of the afterglow shows no significant extinction along the line of sight. The metallicity derived from ion{S}{II} and ion{Fe}{II} of [S/H] = --0.57 $pm$0.25 and [Fe/H] = --1.09$pm$0.24 is relatively high for a galaxy at that redshift but comparable to the metallicity of other GRB hosts at similar redshifts. At the position of the afterglow, no host is detected to F775W(AB) = 28.5 mag with the HST, implying an absolute magnitude of the host M(1500 AA{})$>$--18.3 mag which is fainter than most long-duration hosts, although the GRB may be associated with a faint galaxy at a distance of 11 kpc.