By Agence France-Presse
The 28-year-old suspect was detained and the injured children were receiving hospital treatment, the Mizhi County public security bureau in Shaanxi province said on its official social media account.
Seven girls and two boys were killed, the official Xinhua news agency said, citing local police. The ages of the children were not given, but middle schoolers are usually between 12 and 15 years old in China.
The incident took place at around 6:10 pm local time, the department said.
A man surnamed Zhao from Zhaojiashan village in Mizhi County was arrested, the public security bureau said.
The suspect confessed that he had been "bullied" when he attended the same Number Three Middle School when he was a child, "hated" his classmates and decided to use a "dagger" to kill people on Friday, the bureau said.
A video posted by The Paper, a daily, on video-sharing website Miaopai.com shows two or three bodies lying on the ground in a narrow lane. A person is heard shouting "hurry, call the police!" Police are seen running and later frogmarching a man down the street.
AFP could not immediately verify the authenticity of the video.
Knife attacks are not uncommon in the country.
In February, a knife-wielding man with a personal grudge killed a woman and injured 12 others in a busy Beijing shopping mall -- a rare act of violence in the heavily policed capital.
In the southern city of Shenzhen, a man armed with a kitchen knife killed two people and wounded nine others in a supermarket last July.
History of attacks
Attacks have also targeted schoolchildren in the past, forcing authorities to increase security around schools.
In January 2017, a man armed with a kitchen knife stabbed and wounded 11 children at a kindergarten in China's southern Guangxi Zhuang autonomous region.
The previous February a knife-wielding assailant wounded 10 children in Haikou, in the southern island province of Hainan, before committing suicide.
The man had entered the school in the afternoon, claiming that he was there to pick up his son.
The attacks have led to calls for more research into the root causes of such acts.
Violent crime has been on the rise in China in recent decades as the nation's economy has boomed and the gap between rich and poor has widened rapidly.
Studies have also described a rise in the prevalence of mental disorders, some of them linked to stress as the pace of life becomes faster and support systems wither.
In June last year, a bomb blast that killed eight people and injured dozens outside a kindergarten in Fengxian, eastern China, was blamed on a 22-year-old introvert with health problems who had written the words "death" and "destroy" on the walls of his apartment. Material to make a homemade explosive device was found in the home.