Here's one way...
IF you don't need the bench to be mobile, mount it to the wall. Screw or bolt the horizontal supports to the studs, and then instead of vertical legs, screw or bolt the legs to the front ends of the horizontal supports and run them diagonally to the studs at the floor. This gives a good sturdy workbench without taking up floor space. No legs to trip over, room for your legs if you sit at the bench, and you can still put narrow shelves under it. I went semi-overkill and doubled up the studs I was using for support. The result is not at all springy, but not bang-the-anvil solid. Any really heavy hammering should be done on a dedicated block anyway. I spaced my supports 4' apart, for 4 supports on a 12' long bench. The top is 3- 2x10's. It gets fairly heavy use, mostly in woodworking, and hasn't moved in 30 years.
If you don't have a studded wall - say, a bare concrete block garage wall, I'm not so sure this would be a good way. You'd probably have to bolt the upper supports clear through to the outside. The cantilevered work surface wants to pull away from the wall. Bolting onto the sides of studs provides a really strong tension joint; anchors into masonry, more for shear.
As for attachment, bolts are strongest, then lags and other screws. Nails have the advantage of coming loose before failing completely. Drywall screws have been known to snap without warning. I haven't personally experienced this, but there are too many reports for it to be a complete myth.