The invention discloses an alkyl pyridinium quaternary ammonium salt corrosion inhibitor used for inhibiting carbon dioxide corrosion and a preparation method thereof, and belongs to the technical field of oil field chemicals. The corrosion inhibitor comprises, by weight, composite alkyl pyridinium quaternary ammonium salt, benzalkonium chloride, polyoxyethylene octylphenol ether and / or fatty alcohol-polyoxyethylene ether, thiourea, ethanediol, monoethanolamine and water. The preparation method of the corrosion inhibitor comprises the steps that after being obtained through reactive synthesis of alkyl pyridinium, benzyl chloride, DMF, the ethanediol and the water, the quaternary ammonium salt is compounded with the benzalkonium chloride, the polyoxyethylene octylphenol ether, the fatty alcohol-polyoxyethylene ether, organic solvent, the thiourea, the monoethanolamine and the water. The corrosion inhibitor and the preparation method of the corrosion inhibitor have the advantages that the process route is simple, the synthetic product is free of three-waste pollution, and the cost is low; the raw materials are easy to purchase, and using is convenient.