Mississippi closed all mainland beaches on the state's coastline during the Fourth of July weekend due to toxic bacteria sweeping the state's Gulf Coast.

The Mississippi Department of Environmental Quality (MDEQ) has been closing beaches due to blue-green algae blooms since June.

By Sunday, the spread of the noxious bacteria forced the department to close the state’s last open mainland beach.

Blue-green algae blooms can cause rashes, stomach cramps, vomiting and diarrhea, and state officials also advised against eating fish or seafood from areas affected by the algae.

Beaches on the state’s barrier island remain open, according to the National Park Service, but are being closely monitored. MDEQ said people and pets are welcome to sit on the beach, but are not to go in the water

The blue-green algae, also known as Cyanobacteria, live in water and are the most common type of algae to bloom. The algae often have a distinct musty smell and sometimes look like paint floating on water, according to the National Oceanic and Atmospheric Administration (NOAA).

NOAA says the blooms are happening because of Mississippi River flooding that ravaged the Midwest and Southeast all spring.

To ease the flood waters and prevent the water from reaching New Orleans, authorities opened the Bonnet Carre Spillway, which diverted some of the water to the Mississippi Gulf.

Algae blooms are mainly caused when too many nutrients, like fertilizers, enter a body of water. As water from the nutrient-rich Mississippi River made its way into the Mississippi Gulf's brackish water, it brought the algae with it, NOAA oceanographer Richard Stumpf told NBC News.

Stumpf said the bloom is "not at all surprising." "The water has to flow out, and that's the direction it flows," he said.

Another contributing factor to the algae blooms: climate change.

Larry Brand, a marine biology and ecology professor at the University of Miami’s Rosenstiel School of Marine and Atmospheric Science, told NBC News that while blooms are mainly caused by excess nutrients, "algae also like higher temperatures."

"As the earth gets warmer, you can get more and more blooms," Brand said.

The extreme weather that climate changes causes often leads to massive rain storms and floods, which Brand says moves fertilizers from soil into bodies of water. As this becomes more common, so too might algae blooms.

And there's no real way to stop a bloom once it happens in a large body of water.

"You're going to have to wait for the tides to flush it away," Brand said.