The phrase “mind your P's and Q's” is often used to remind people to be careful, and to remain on their best behavior. It appears to have emerged around the 1600s, and the exact origins are actually a bit murky. There are a number of theories to explain the roots of the idiom, although these theories are of varying levels of believability. Ultimately, the history behind this phrase may never truly be known.
One of the most likely theories about “mind your P's and Q's” is related to the pints and quarts served at bars. Many bars and pubs traditionally kept track of customer tabs on a large slate board, adding up the P's and Q's at the end of the night. A smart customer would keep an eye on this list to ensure that the bartender was not fudging the numbers. Some bartenders have also theorized that bar staff may have been admonished to mind their P's and Q's, by keeping track of how many drinks they dispensed over the course of the night.
In this sense, one would also need to remain relatively sober to keep a sharp eye out. This sobriety would, of course, result in a generally better standard of behavior. This explanation for the phrase is one of the most widely accepted, since it seems like the most rational.
Some printers have suggested that the term may be related to typesetting. Movable type is cast backward so that it will print the right way, and lower case P's and Q's are easily confused in the type case, since the letters are mirror images of each other. Of course, the same could be said of lower case B's and D's, and the phrase is not “mind your B's and D's.”
A young child who is learning to read and write may also be reminded to “mind your P's and Q's,” as the lower case letters can be confused. This explanation is also weak, however, since P's and Q's appear far less commonly than B's and D's in writing, and surely people who are learning how to read could mistake these letters as well. Furthermore, spelling things correctly has no clear link with good behavior, and since many people use the term in the sense of behaving, these explanations both leave something to be desired.
Some people also say that “mind your P's and Q's” is a chess term, as in “mind your pawns and queens.” One would certainly want to keep track of both pawns and queens, as these pieces can be crucial in a chess game. However, there is not a clear and obvious link between playing chess well and behaving well, so this explanation seems a bit weak.