Police said the suspect was 26 years old and born in the United Arab Emirates. They said he acted alone and he was overpowered by passersby.
Mayor Olaf Scholz said the attack was motivated by "hate" but did not say it was a terror attack.
There are unconfirmed reports that the man shouted "Allahu akhbar", Arabic for "God is great" while attacking people.
Police said they were still seeking to confirm his current nationality. Mr Sholz said he was a failed asylum seeker.
The man attacked customers in the supermarket at random, ran outside and was chased by customers and by people outside the shop. They brought him to the ground before he was detained by plain-clothes police officers.
Mobile phone footage on German media that is purportedly of the attack's aftermath shows several people chasing a man and throwing chairs at him.
A 50-year-old woman and four men aged between 19 and 64 were stabbed, while a 35-year-old man was injured while helping overcome the suspect.
The attack happened in the Barmbek region in the north of the city in a branch of Edeka, Germany's largest supermarket chain.
Police say the man's weapon may have looked like a machete but they are, for now, assuming it was a kitchen knife.
One eyewitness made a gesture about 50cm (20 in) long when asked on German TV how big the knife was.
Asked whether this was a terror attack, a police official told the BBC: "We are at an early stage of the investigation... At the moment we can't rule anything out. We are investigating all avenues."
Speculation in German media said the attack may have been part of a robbery attempt but police said that that motive could not be confirmed.
One eyewitness, who ran from the scene into a nearby shop as the situation unfolded, told German broadcaster NTV that it seemed "hectic and confused, not like a properly planned attack".
A 50-year-old German man has been killed and six people injured in a knife attack in a Hamburg supermarket.