Victory means the Millers are now unbeaten in 18 games but they were pushed all the way by a Stockport team who appeared inspired by vocal away support.
Ashley Palmer was another to go close to a leveller for the visitors in the second half when his header sailed narrowly wide.
As Dave Challinor’s men searched for a goal, Rotherham looked dangerous on the break but were unable to double their advantage against a side 55 places below them in the league pyramid.
The draw for the third round takes place on Monday at 19:00 GMT.
Rotherham boss Paul Warne told BBC Radio Sheffield:
“There are no easy victories, we knew it was going to be really tough. They were really well-organised, there [away support] was amazing, the best we’ve ever had here.
“There was a lot of pressure from Stockport, a lot of set-pieces going into our box.
“We just needed that second goal, that would have settled us down a bit. The last 10 minutes we were hanging on.
“In the end I’m really pleased with the result but I’m not that over the moon with the performance.”
Stockport manager Dave Challinor:
“I thought we deserved something from the game but it also showed the fine margins when you come up against teams from a higher level because I’m sure, when the lads watch the game back, they will be disappointed with the goal that cost us the game.
“We played too many sloppy passes and gave the ball away 25 yards from goal then, three passes later, the ball ended up in our net.
“I don’t think anybody would have noticed the two-division difference between the teams, so I’m pleased with that aspect, but I hate losing and I’m just disappointed to be out of the cup.”
6WoodSubstituted forHardingat 45′minutes
4BarlaserSubstituted forOdoffinat 81′minutes
14MillerBooked at 38minsSubstituted forMattockat 81′minutesBooked at 90mins
18RathboneSubstituted forLindsayat 65′minutes
10LadapoBooked at 70mins
24SmithBooked at 39minsSubstituted forGriggat 75′minutes
6BarclaySubstituted forHoganat 77′minutes
3KitchingSubstituted forRaikhyat 85′minutes
7Southam-HalesBooked at 60mins
14CollarBooked at 20minsSubstituted forMaddenat 55′minutes
18CroasdaleSubstituted forRooneyat 85′minutes
23SarcevicBooked at 87mins
27CrankshawSubstituted forJenningsat 77′minutes
Match ends, Rotherham United 1, Stockport County 0.
Second Half ends, Rotherham United 1, Stockport County 0.
Foul by Hakeem Odoffin (Rotherham United).
Macauley Southam-Hales (Stockport County) wins a free kick in the defensive half.
Corner, Rotherham United. Conceded by Arjan Raikhy.
Corner, Stockport County. Conceded by Hakeem Odoffin.
Corner, Stockport County. Conceded by Michael Ihiekwe.
Joe Mattock (Rotherham United) is shown the yellow card.
Antoni Sarcevic (Stockport County) wins a free kick in the defensive half.
Foul by Joe Mattock (Rotherham United).
Joe Mattock (Rotherham United) wins a free kick in the attacking half.
Foul by Macauley Southam-Hales (Stockport County).
Antoni Sarcevic (Stockport County) is shown the yellow card.
Michael Ihiekwe (Rotherham United) wins a free kick in the attacking half.
Foul by Antoni Sarcevic (Stockport County).
Substitution, Stockport County. Arjan Raikhy replaces Mark Kitching.
Substitution, Stockport County. John Rooney replaces Ryan Croasdale.
Attempt saved. Ashley Palmer (Stockport County) header from the centre of the box is saved in the centre of the goal.
Foul by William Grigg (Rotherham United).
Mark Kitching (Stockport County) wins a free kick in the attacking half.