In one scene in Master and Commander, an officer points out to a younger shipmate the captain's initials, carved about 20 years ago. Was staying with one ship for 20 years unusual for this period of time? What about for enlisted or impressed sailors?
In general, sailors would only stay aboard a ship until the commission it was on was paid off. There are some terms of art in there, so let me explain:
The idea of having a permanent crew aboard a ship or a permanent term of enlistment in the navy didn't really apply outside of a few petty officers who were semi-permanently attached to their ship. I wrote about this more here.
For most of the crew and the officers, they would enlist for a commission that could last for an indeterminate period, and ships would be paid off at the end of that time -- that is, the crew would actually receive a ticket for their wages after a period ranging anywhere from a few months to a few years.
Officers were paid more regularly, by the (lunar) month, but they again had no real fixed period of service with the navy. Officers had access to something called half-pay, which was a payment of (you guessed it) half their wages when they weren't actively employed aboard, to keep them tied to the Navy for future service.
In the case of Master and Commander, the movie (based not on the book Master and Commander, but on The Far Side of the World,) the author's conceit is that the captain, Jack Aubrey, had served on the ship as a midshipman (an officer in training) before later, after a series of other commissions, returning as a post-captain to command the Surprise.