Mending is a treasure enchantment, which means it never appears as a normal enchanting table option. The only ways to get it are trading with a librarian villager, fishing, or finding it in chest loot inside a jungle pyramid, stronghold, or ancient city.
Trade with a librarian
A librarian villager can offer a Mending book at any trade level, not just their highest tier. Each librarian has a random chance to roll Mending among their possible enchanted book trades, the same odds as any other enchantment on that villager's trade table. If your current librarian does not offer it, you can reset the offers by breaking and replacing the lectern the villager is working at, which forces a new, unemployed villager to re-pick a profession and roll a fresh set of trades. This can take anywhere from a handful of tries to over a hundred, since it is random every time.
Fish for it
Fishing with a normal rod has a chance to pull up an enchanted book as part of the treasure loot category, and Mending is one of the enchantments that can appear on that book. Using a rod enchanted with Luck of the Sea raises the odds of landing treasure loot in general, which indirectly raises your chances of a Mending book, though it is still a matter of chance.
Loot it from a structure
Mending books can spawn in chest loot inside jungle pyramids, strongholds, and ancient cities. These are slower sources since you need to find and clear the structure first, but they do not depend on an existing villager or boat.
Combining Mending onto an existing item
Once you have a Mending book, you don't need to find a brand-new tool to use it on. An anvil lets you combine an enchanted book with an existing sword, pickaxe, bow, or piece of armor, adding Mending to that item alongside whatever enchantments it already has, as long as the item has a free enchantment slot for it. Each enchantment added through an anvil raises the item's prior work penalty, so an item that has already been combined several times can become expensive to enchant further, sometimes to the point where the game blocks the combination with a Too Expensive message. For that reason, many players add Mending early, before stacking on other costly enchantments, rather than saving it for last.
Which method is fastest
Trading with a librarian is generally the quickest route if you already have a few villagers and an emerald supply, since it only costs time spent resetting lecterns rather than exploring. Fishing is the slowest in terms of guaranteed progress, because most catches are junk or fish rather than treasure, and even a treasure catch is not guaranteed to be an enchanted book, let alone one with Mending specifically. Looting structures sits in between: a single successful ancient city or stronghold run can turn up a Mending book directly, but getting there and surviving the trip takes longer than a few lectern resets in an existing village.
What Mending actually does
Once an item has Mending, every experience orb you pick up while that item is equipped (or in your main hand or offhand) can repair it instead of adding to your experience bar. The game repairs two points of durability per point of experience in the orb, and it picks one damaged, Mending-enchanted item at random each time an orb is collected, so wearing a full set of Mending armor spreads repairs across all four pieces rather than hitting one at a time. Mending cannot be combined with Infinity on the same item, since the two are mutually exclusive in survival.
FAQ
Can I get Mending from an enchanting table?
No. Treasure enchantments like Mending are excluded from the normal enchanting table pool, so an anvil, a librarian trade, fishing, or chest loot are the only routes.
Why does my librarian keep offering the same trades?
A librarian locks in its trades once it becomes employed at a lectern. Breaking the lectern turns it back into an unemployed villager, and giving it a new lectern makes it roll a new set of trades, including a fresh chance at Mending.
Does the villager's biome affect the chance of getting Mending?
No, outside of the optional Villager Trade Rebalance experimental feature, biome and outfit do not change which trades a librarian can offer. Every librarian has the same pool of possible enchanted books.
Is Mending worth putting on armor or only weapons?
It works the same way on any item that supports it, including armor, so a full Mending armor set stays repaired passively just from normal experience gains while mining, fighting, or farming. Since only one damaged item is repaired per orb, spreading Mending across four armor pieces means the repair gets divided among them rather than fixing one piece instantly.
If you are planning to put Mending on a trident, check the Ancient City guide for another place Mending books can drop, and see the Minecraft game hub for more survival guides.