The invention discloses an application of N-acetyl-L-cysteine in preparing a drug for treating or preventing porcine virus infection. The application comprises the steps: A, preparing N-acetyl-L-cysteine, absolute ethyl alcohol, tween-80, lactose, soluble starch and bran into a granule, oral liquid or powder, B, adding the granule, the oral liquid or the powder into feed or drinking water, or C, independently administering N-acetyl-L-cysteine, D, continuously using N-acetyl-L-cysteine during a whole feeding period as preventive addition and long-term usage in the feed, E, feeding the powder and the granule directly for treatment, or F, mixing the powder and the granule with daily ration, adding into the feed in the morning, at noon and in the evening every day, and continuously using the powder and the granule. N-acetyl-L-cysteine has high safety, no toxic or side effects, and antiviral activity, and can effectively prevent and treat the porcine circovirus type 2 and porcine epidemic diarrhea virus infection, reduce a mortality rate of infected pigs, and effectively increase a survival rate and productivity of the pigs.