With Silver Bells and cockle shells and pretty maids all in a row.
The origin of this nursery rhyme is disputed. The oldest know print version is from Tommy Thumbs pretty song book published in 1744.
With the invention of the printing press, It was becoming much easier to print and circulate stories and rhymes that had only been spoken or hand-printed over many years, even centuries. A time which was also becoming known as the 18th century, “Age of Enlightenment”. As more printing presses were produced, more types of information was published at prices that the general public could afford. More people learned to read. Its not surprising to see how variations on the old standard nursery rhymes might sell more books. To learn more about this, go to the Wikipedia page Mary Mary Quite Contrary.
Queen Mary, also known as Mary Tudor and Bloody Mary is thought to be an inspiration for the rhyme.