The invention discloses a formula of a medicine for preventing and treating dairy cow mastitis. The medicine is composed of bulk drugs of, by weight, 30 parts of codonopsis pilosula, 35 parts of rhizoma atractylodis macrocephalae, 40 parts of poria, 50 parts of radix scutellariae, 35 parts of pericarpium citri reticulatae, 30 parts of radix bupleuri, 100 parts of dandelion, 50 parts of veratrum nigrum, 40 parts of astragalus membranaceus, 30 parts of angelica sinensis, 20 parts of radix angelicae, 60 parts of herba houttuyniae, 50 parts of fructus forsythiae, 55 parts of herba patriniae, 50 parts of uniflower swisscentaury roots, 55 parts of snakegourd fruit, 20 parts of cassia twigs, 45 parts of cowherb seeds, 25 parts of caulis akebiae, 50 parts of medicated leaven, 35 parts of burdock, 40 parts of chrysanthemum indicum, 55 parts of philippine violet herb, 30 parts of olibanum, 30 parts of myrrh, 30 parts of fritillary bulbs, 40 parts of radix trichosanthis, 35 parts of prunella vulgaris, 50 parts of oyster, 40 parts of pericarpium citri reticulatae viride, 40 parts of herba schizonepetae, 30 parts of radix sileris, 40 parts of beautiful sweetgum fruit, 30 parts of ligusticum wallichii, 30 parts of walnut kernels, 10 parts of flos carthami, 90 parts of motherwort and 50 parts of terrestrial branch medicines. The medicine is effective in treatment and reliable in effect and has no toxic and side effects, the total effective rate is 90.5%-96.9%, and the cure rate is 82.4%-91.5%.