  Motivated by the intriguing discrepancies in $b\to s \ell\ell$ transitions,
the fermion mass problem, and a desire to preserve the accidental symmetries of
the Standard Model (SM), we extend the SM by an anomalous $U(1)_X$ gauge
symmetry where $X=Y_3+a(L_\mu-L_\tau)/6$. The heavy $Z^\prime$ boson associated
with spontaneously breaking $U(1)_X$ at the TeV scale mediates the $b\to
s\ell\ell$ anomalies via $\mathcal{O}^\mu_9
\sim\frac{1}{\Lambda^2}(\bar{s}\gamma_\rho P_L b)(\bar{\mu} \gamma^\rho \mu)$.
We show that this model, which features mixed gauge anomalies involving
$U(1)_X$ and hypercharge, can be made anomaly-free for any $a\in \mathbb{Z}$ by
integrating in a pair of charged fermions whose masses naturally reside
somewhere between 1 and 30 TeV. The gauge symmetry permits only the third
family Yukawas at the renormalisable level, and so the light quark masses and
mixings are controlled by accidental $U(2)^3$ flavour symmetries which we
assume are minimally broken alongside $U(1)_X$. The lepton sector is not
governed by $U(2)$ symmetries, but rather one expects a nearly diagonal charged
lepton Yukawa with $m_{e,\mu} \ll m_\tau$. The model does not explain the
hierarchy $m_e\ll m_\mu$, but it does possess high quality lepton flavour
symmetries that are robust to the heavy physics responsible for generating
$m_{e,\mu}$. We establish the viability of these models by checking agreement
with the most important experimental constraints. We comment on how the model
could also explain neutrino masses and the muon $g-2$.
