How can I treat an infected ear piercing without having to take my earring out? My piercing is brand new and started to swell 2 days after piercing it

Remove earring. That may be the source of infection or it may not be pure gold.A common problem is other metals, notably nickel, are present and this is an allergic reaction, not infection.
Use 14 caract gold. It is important to remove the earring to wash in hydrogen peroxide. Clean your earlobe. Most importantly check to verify the type of metal use to make the earring. Most people are allergic to nickel. Use 14 carat gold.
You can't. If your ear piercing is infected, you will need to take out the earring. Additionally, you may need to see a medical professional for oral and topical antibiotics. Some suggest hibiclens as a surgical scrub, but take care not to get it in your ear as it can have a negative effect on your ear drum. Another possibility is that you are allergic to the metal in the earring- you may need platinum!