If your dog bites you, yell at him loudly and release your hand to let him know that you are not playing with him. If your dog tries to bite you again, tell him not to bite and leave the room for 10-20 seconds. If they continue to bite, leave them alone for a longer period of time so they learn this is bad behavior.
Why do dogs bite?

A dog may bite someone to defend itself, its territory, or a member of its pack. A mother dog may also be overprotective of her puppies. Startling a dog awake or suddenly approaching it from behind can provoke it to bite.
How to avoid dog bites
Give your dog at least basic training and continue your dog’s training program throughout his life to reinforce the lessons you have taught him. Socialize your dog. Allow your dog to meet and interact with a wide variety of people, including children, people with disabilities, and older people, etc., in calm, positive circumstances.
Regularly expose your dog to different situations such as other dogs, loud noises, large machines, bicycles, or anything else that may cause his fear. Start this training with your dog at an early age and keep the experience positive.
Pay attention to your dog and know when things may trigger aggression. If you can’t control the situation or your dog’s behavior, you may have to remove your dog before things get out of hand.
If your dog bites someone
If your dog bites a person, it is important to take immediate action. First take the dog under your control and then immediately help the injured person. If possible, the victim should wash the bite site thoroughly with soap and warm water and then seek medical attention immediately.