The etymology (word history) of most of the days of the week are linked to Roman mythology. The Romans saw a connection between their gods and the changing face of the nighttime sky, so it became natural to use their gods' names for the planets — the ones they were able to track in the sky were Mercury, Venus, Mars, Jupiter and Saturn. Those five planets plus the moon and sun made seven major astronomical bodies, so when the seven-day week was imported from Mesopotamia early in the fourth century it was a natural to use those astronomical names for the days of the week.
Eventually, the first day of the week was named after the sun, followed by the moon, Mars, Mercury, Jupiter, Venus and Saturn. The names of the week were adopted with little change throughout most of the Roman Empire and even beyond. In only a few cases were changes made.
In Spanish, the five weekdays all retained their planetary names. Those are the five days whose names end in -es, a shortening of the Latin word for "day," dies. Thus lunes comes from the word for moon (luna), and the planetary connection is also apparent with martes (Mars, Tuesday), miércoles (Mercury, Wednesday) and viernes (Venus, Friday).
The connection with Jupiter is not quite so apparent with jueves, the word for Thursday, until you remember that "Jovian" is the adjective form of Jupiter in English, coming from a Latin root.
In Spanish, that leaves the words for Saturday and Sunday that weren't adopted using the Roman naming pattern. Domingo, the word for Sunday, comes from a Latin word meaning "Lord's day." And sábado, the word for Saturday, comes from the Hebrew word Sabbath, meaning a day of rest (in Jewish and Christian tradition, God rested on the seventh day of creation).
In English, the pattern is similar, but with a key difference. The connections between Sunday and the sun, between Monday and the moon, and between Saturn and Saturday should be obvious. The difference with the other days is that English is a Germanic language, and the names of equivalent Germanic gods were substituted for the Roman gods.
Mars, for example, was the god of war, while the Germanic god of war was Tiu, whose name became part of Tuesday. Wednesday is a modification of Woden's Day; Woden was a god who was swift like Mercury. You may have heard of the Norse god Thor; a variation of that name was the basis for naming Thursday. Finally, Frigg, after whom Friday was named, was like Venus a goddess of love.
Sources: American Heritage Dictionary, Diccionario de la Real Academia Española