Eco-friendly self-doped carbon quantum dots (ZCQDs) with excellent corrosion inhibition ability were prepared via solid-phase pyrolysis only using Zanthoxylum bungeanum leaves as the raw material. Compared with the relevant research, a simpler and higher yield (25%) preparation process for carbon quantum dots was proposed. ZCQDs were characterized by transmission electron microscopy and X-ray photoelectron spectroscopy, and the average size of ZCQDs with multitudes of O- and N-containing functional groups was about 2.53 nm. The prepared ZCQDs were used to inhibit the corrosion of Q235 steel in HCl solution, and the inhibition behavior was investigated through weight loss, electrochemical test, surface analysis, and adsorption thermodynamic analyses. The results showed that the ZCQDs, acted as a mixed corrosion inhibitor, have an effective corrosion inhibition for Q235, the corrosion inhibition efficiency reached 95.98% at 200 mg/L, and at this concentration, effective protection of at least 132h (IE > 90%) is provided. Moreover, the adsorption mechanism of ZCQDs was consistent with that of Redlich-Peterson adsorption, including chemisorption and physisorption. A new corrosion inhibition mechanism of ZCQDs has been thoroughly studied and proposed; ZCQDs have functional groups containing O and N, which can form a protective barrier through physical adsorption and chemisorption, but the coverage of the protective film is low at low concentrations. With the increase of concentration, the protective film formed by ZCQDs on the metal surface will first increase the coverage and then adsorb more ZCQDs on the protective film to form a thicker and denser protective film to protect the metal. The carbon quantum dots prepared in this paper have advantages including a green, renewable precursor, a fast method, high yield, and excellent corrosion inhibition. Therefore, this work can inspire and facilitate, to a certain extent, the future application of doped carbon quantum dots as efficient corrosion inhibitors in HCl solutions.