The name of the city of Khachmaz is mentioned in 17th-century sources. The location of the city on the caravan trade routes led to its rapid development. The location of the city on the bank of the Gudyalchay is probably not accidental, because Niyazabad, a well-known port at that time, was located at the mouth of this river. The construction of the Khachmaz station on the Baku-Makhachgala (Petrovsk) railway, which was completed at the beginning of the 20th century, turned the city into an important transportation point. In 1930, the city became the district center. The Khachmaz cannery, built-in 1945-1954, was one of the largest enterprises in terms of production capacity on the European continent for a long time. Khachmaz was declared the capital of legends of the Republic of Azerbaijan in 2013 by the Ministry of Culture and Tourism in accordance with the "Capitals of People's Creativity for 2010-2014" Program.