|Is this a laptop computer or a desktop computer ?|
You probably have either a physical problem in the port, or a problem with the device's cable.
Check the USB plug on the device's cord and the USB port you are plugging it into.
The rectangular plastic blocking plug that prevents you from plugging in the plug upside down should not be loose or missing.
There should be no bent contacts in the plug or in the port.
The plug's outer metal shell should not be bent such that it's loose in the USB port.
The outer metal shell of the USB port should not be bent (stretched) such that any USB plug is a loose fit.
Use a USB port that's in better physical condition if you need to.
If everything looks to be physically okay, it's common for wires inside the cable for a corded mouse or keyboard to get broken after the mouse or keyboard has been used a lot, especially if you have been pulling on the cord to unplug it rather than pulling on the plug, or at any time if you have yanked on the cord. If a wire has broken but it's insulation is still intact, the connection of that wire will be intertmittant and unreliable - depending on what position the cable is in, the device will work sometimes, not work other times - often if you wiggle the cord near where it enters the plug or the device, the device will do that.
If you are using an external multport USB hub that plugs into one USB port built into the computer's mboard, it's well known that not all devices will work properly when plugged into that type of hub, especially when more than one device is plugged into it.