system
Given the following post, respond as if you're commenting on Reddit:
human
Can you become immune to strains of bacteria?

I was under the assumption that you only become immune to viruses, but not bacteria. Is that true, and if so why?
gpt
You can definitely become immune to strains of bacteria.

Immunity is subdivided into two categories: innate and adaptive immunity.

Innate immunity are those features of our immunity that are static and use a somewhat "generalized" approach to protecting the individual. This includes things like the Toll-like receptors and mannose binding lectin that have broad specificity for different types of pathogens, including bacteria.

Adaptive immunity relies on the production of antibodies. Antibodies are globular proteins encoded by genes the have what's called a "hyper variable region".  A staggering array of mutations occur in these regions during development of a newborn, giving rise to a large array of B cells encoding antibodies that are each unique to a different antigen and expressing it on their surface. In a process called clonal selection, B cells expressing antibodies that bind to proteins from yourself are killed off, otherwise an autoimmune disease develops. Once clonal selection occurs, any antigen that binds to an antibody on the surface of a B cell (including antigens on bacteria) will trigger a cascade of responses in which the B cell starts multiplying and the B cells start excreting the antibody they encode. These antibodies can then start binding to pathogens and mediating the adaptive immune response. 

The concept of "gaining immunity" refers to priming/activating B cells that encode antibodies that bind to a specific pathogen. When an antigen binds and activates a B cell and initiates the adaptive response, some of the B cells that proliferate are fated to become so called "memory B cells" that persist at higher levels in the blood stream to allow the body to start responding to the same infection much faster during subsequent exposure. 

If an antigen from a bacterium activates its cognate B cell and stimulate formation of memory B cells that encode antibodies specific to the bacterium, you've gained immunity to it.