Mantra (Sanskrit) is any word, phrase, or prayer, chanted aloud or mentally, used as a form of meditation practice, basically as a meditative tool, to center, calm, and focus the mind. There are mantras in almost every religious, spiritual, and contemplative tradition. I'll offer some here from some of the major traditions. But you are encouraged to construct your own, one that is meaningful for you. I also encourage you to see if you can coordinate the rhythm of the mantra with that of the breath, and/or with your pace walking, jogging, swimming, or engaging in any other repetitive activity. Based on their different meanings, different mantras might bring about different emotions and states of mind. (If you want to skip the explanations, click here to go my Mantra Meditations page to hear sample mantras.)
For example, a devotional mantra chanted to one's guru, to the Buddha, to Jesus, or to some conception of God that one identifies with and towards which one has faith might likely put one in the spirit, so to speak, a felt sense of communion with the being that one is chanting to, as with prayer. Or, in trying to motivate oneself, say, when training for a marathon, one can chant some word or phrase that inspires energy, such as "finish line", "in the zone", "runner's high", or something more personal.
On the other hand, one can simply breath in "new" and out "old". Or one may literally chant any meaningless word for a similar effect: as J. Krishnamurti once said, once can even chant "coca cola" to somewhat hypnotize oneself. From his perspective, meditation is not something one does; it is a state of being that arises when one is free of all doing, wanting, trying.
My philosophy on this is: whatever works for you, works for you. If it does, then naysayers about what works for you are obviously mistaken in your case. Don't uncritically let anyone, not even your favorite philosopher (and Krishnamurti is one of my all-time favorites), meditation master, guru, or spiritual teacher, tell you what to do or not to do, but don't entirely dismiss their ideas either: the point is to consider them, and then decide for yourself, based on your best understanding of everything you know, especially your knowledge of yourself, your intentions, and your circumstances.
One good purpose for which mantras work is to clear the mind of chatter, particularly when nothing else will work. A mantra is like a broom that sweeps away whatever else was on your mind. It works like an "ear worm", a song, TV commercial or jingle you cannot get out of your mind, once you hear it, so it is particularly useful to override any other ear worms. It is recommended to chant the mantra aloud whenever you can (when alone or chanting in a group), but silently is fine once the mantra has developed some momentum in your psyche. Once it has built momentum for you, a single thought of the mantra can trigger its effortless spinning in your mind. If you habitually chant it while jogging, for example, after some time all you need to do is to begin jogging, and the mantra automatically starts playing in your mind, without you even thinking about it: you'll just notice that it has begun on its own. Meditation is like that in general, which is why it is useful if you can have a posture you reserve for meditation, such as sitting cross-legged on a cushion, because the mere placement of your body in the unique-to-meditation posture, once habitual, triggers the meditative mind effortlessly.
One reason mantra works so well to clear and calm the mind, on my analysis, is that it puts to work that part of the mind that would otherwise be generating thoughts, what we call internal dialogue, what the contemplative traditions call "monkey mind", the discursive-thoughts-generating part of the mind that constantly spews forth commentary about everything you're experiencing:
judgments, evaluations, comparisons, criticisms, associations, memories, regrets, worries, fears, and so on. By putting the thinking mind to the task of thinking/chanting the mantra, by giving it the kind of focal point that it needs to make a mental effort to keep generating (you need to think the mantra to repeat it to yourself), that tends to utilize all the thought energy that would otherwise be disbursed in habitual mind-wandering chatter and internal dialogue that typically overwhelms the meditating mind.
The same explanation applies to almost any other meditation technique that involves some sort of mental doing, such as counting or visualizing: they work well because they put the thinking mind itself right into the meditative task. These techniques, however, are preliminaries that function as props, tools, or supports (like training wheels are for learning to ride a bike), that hopefully bring you into a state of mind that is calm enough to be ripe for meditation to happen. The deeper meditative states are things that typically seem to happen, rather than things one seems to do. They typically involve a state of being, not necessarily any kind of doing. However, rich meditative states can accompany and arise while doing almost anything, once you have a solid practice. The deeper one's practice, the more meditative states seem to happen, whether one is doing anything to prompt them or not.
For some of my favorite mantras, which you can read (as well as their translations) and hear how they are chanted, click here to go to my Mantra Meditations page. Some of them may be chanted with different melodies, which I also sample.