You pretty much eliminated software problems leaving you with hardware.
USB is a couple of pins in a set arrangement connected by aluminium/copper wires (which are normally soldered or even worse held together by an interference fit).
At various points you pull on/bend them which tends to loosen the solder joint/pull the wires from the interference fit or subject the wires to fatigue failure (fatigue involves small crack getting larger and larger until the small force becomes enough to snap the wire: you probably have done this with a drinks can which brings me to a second point: aluminium is very prone to this failure method and copper is not so hot either)
Now there are two possibilities: the wire and the port.
Fixing, if it is just solder joint open it up and simply melt and allow the solder to reform (you can add a bit more or replace it if you like). You can do this for the port (be damn careful if it is on your motherboard, front facing and the like should not be a problem). Interference I would be tempted to solder for as I really do not like this joining method for something like this (in case you had doubts designers make this kind of mistake all the time: I have lost count of how many solder joints have failed due them being load bearing and how many people have went and got new stuff because of this).
The wire can be a bit harder to fix as they normally are not designed to be opened up and even then the break can be somewhere in the wire other than the connection ends). You can get a lead from somewhere (old USB devices and wires are not hard to come by for me) and solder that at the device end in the case of the mouse.
If after a quick/temporary fix get a USB extension and attach that if you need to the port before plugging your device in the other end, now instead of a fixed point your mouse/keyboard has to move against it will be a free end of an extension.