Sugar is a common name for a large family of sweet-tasting crystalline carbohydrates that includes both monosaccharide and disaccharide forms. Some common monosaccharides are fructose (found in honey and fruits), galactose (found in milk), and glucose (which is the primary source of energy for living things). These come together in different combinations to form disaccharides such as sucrose (common table sugar, which is glucose + fructose) and lactose (milk sugar, which is galactose + glucose).
Looking at sucrose specifically, the primary source in the ancient world was sugarcane (Saccharum genus), a tall, perrenial grass native to the Indian subcontinent and tropical Asia. By the 5th century, they had figured out how to crystallize out sugar from sugarcane juice. The Arab Empire took the small scale production of crystallized sugar and figured out how to ramp up production, eventually introducing mills, refining processes and sugarcane plantations. By the 8th century, they had spread this knowledge into Europe, where sugar competed with honey as the primary sweetener. The English word for sugar comes from the Arabic sukkar.
In 1492, Christopher Columbus received sugarcane cuttings from the govenor of the Canary Islands, and he took these to the New World, where sugarcane plantations and refineries quickly developed. As a byproduct of the refining of sugarcane juice, molasses was used to produce rum.
Today, sugar beets and sugarcane are the primary sources of sugar -- they store energy from the sun as sucrose instead of the more common glucose. Sugar can be as simple as evaporated sugarcane juice, and as complex as snowy white fine-grained table sugar. Sugar ranges in color from white to pale brown to molasses-brown. These darker colors of sugar are typically referred to as unrefined, and include things like Muscovado and Demerrara sugar, powdered sugar, which is very fine and contains cornstarch, jaggery from India and piloncillo from Mexico.
Sugar is rarely used in processed foods, as corn syrup is cheaper and easier to use in most applications. In high enough quantities, sugar retards the grown of bacteria, which makes it useful in preserving foods. In lower quantities, sugar provides mouthfeel to cocktails.
Sugar is incredibly important to the development of the cocktail. In fact, by the strict definition, the cocktail is spirit, water, sugar and bitters. While older cocktail recipes call for sugar in a granulated or cube form (like in the Champagne cocktail) where the sugar is wet with bitters and muddled briefly to dissolve it, modern cocktails are more likely to rely on simple syrup so that the sugar is dissolved before being added to the drink.
Refined sugar has a simple, sweet note. As such, it naturally opposes flavors that are sour, and partially moderates bitter flavors.