In 1846, he was assigned to USS "Mississippi", flagship of the West Indian Squadron Serving under Commodore Matthew C. Perry. During the Mexican–American War, he took part in expeditions against Alvarado, Tampico, Pánuco, and Laguna de Términos, all successful in tightening American control of the Mexican coastline and interrupting coastwise commerce and military supply operations. The ship returned to Norfolk for repairs on 1 January 1847, where Anderson was promoted to lieutenant. Mississippi then returned to battle, arriving at Veracruz on 21 March 1847, carrying Perry to take command of the American fleet. At once she and her men plunged into amphibious operations against Veracruz, supplying guns and their crews to be taken ashore for the battery which fought the city to surrender in four days. Through the remainder of the war, "Mississippi" contributed guns, men, and boats to a series of coastal raids on Mexico's east coast, taking part in the capture of Tabasco in June 1847.