There is no ham in a hamburger. The "ham" is part of a city's name, and a German would read the word as "someone from Hamburg."

That is how English first used it. Etymonline records hamburger in the 1610s for a native of Hamburg, and also for ships from the city. The food sense grew out of a series of dishes named after the port.

The path runs through beef. Etymonline finds "Hamburg beef," a smoked and spiced beef hash, by 1767. "Hamburgh sausage" appears in 18th-century editions of Hannah Glasse's cookbook, and Etymonline dates the term to 1774. "Hamburg steak," a dish of chopped beef, is recorded by 1880. American menus listed it in the 1870s and 1880s.

Why Hamburg? Nobody knows for sure. Etymonline says no certain connection with the city has been shown. It suggests the city's role as a major port of departure for German emigrants to the United States. Wikipedia also calls the exact link contentious.

The sandwich is an American story, and a crowded one. Several people are credited with first serving the patty between bread. Charlie Nagreen claimed he did it at the Seymour Fair in 1885. The Menches brothers claimed the Erie County Fair in Hamburg, New York, that same year. Louis' Lunch in New Haven credits Louis Lassen around 1900. Others back Fletcher Davis of Athens, Texas, or Oscar Weber Bilby in 1891. Wikipedia says no conclusive argument has ended the dispute.

The name for the sandwich is easier to date. Etymonline finds "hamburger sandwich" by 1902 and the bun-and-patty sense by 1909. The 1904 St. Louis World's Fair helped make it a national food.

Then English split the word in a new place. Instead of Hamburg plus "-er," it became "ham" plus "burger," and "-burger" took on a life of its own. Etymonline records the clipped form burger by 1939 and cheeseburger by 1938. Beefburger followed in 1940, to make clear what the patty was made of.

The city's name has its own meaning. The "-burg" is a fort, from a moated castle built there around 825. The "Ham-" is less certain. It may come from a word for a bend in a river, or from one for enclosed pasture.