Gandalf is not a "wizard" in the classical fantasy sense of the word, one whose power and wisdom is learned in dusty towers poring over old books.
He is a divine being, one of the Maiar, whose very essence is wisdom.
Indeed, it can be interpreted that the Ainur (the Maiar and the Valar) are all aspects of the universal divinity, each embodying some quality:
[Eru, the Creator] made first the Ainur, the Holy Ones, that were the offspring of his thought, [...]
But for a long while they sang only each alone, or but few together, while the rest hearkened; for each comprehended only that part of the mind of Ilúvatar from which he came, and in the understanding of their brethren they grew but slowly.
Yet ever as they listened they came to deeper understanding, and increased in unison and harmony.
(From the Ainulindalë, the Music of the Ainur, in the Silmarillion.
Emphasis mine).
So some of Gandalf's wisdom is inborn, a part of his essence.
But some he learned from other Maiar or the Valar themselves: Wisest of the Maiar was Olórin [=Gandalf's name in Valinor] .
He too dwelt in Lórien, but his ways took him often to the house of Nienna, and of her he learned pity and patience.
(From the Valaquenta, in the Silmarillion).
scifi.stackexchange.com/users/4516/Avner Shahar-Kashtan
Gandalf was partially taught by the Vala Nienna, per the Silmarillion, Valaquenta: Wisest of the Maiar was Olórin.
He too dwelt in Lórien, but his ways took him often to the house of Nienna, and of her he learned pity and patience .
(My emphasis, with Olórin, of course, being Gandalf's original name as a Maia in Valinor)
This is, as far as I know, the most that Tolkien ever wrote on the subject.
scifi.stackexchange.com/users/None/
Gandalf has no teacher.
He is a Maiar, something like a demi god.
He was born like this.
And he knows much more than what he showed on LOTR, because when he was in Middle-Earth he couldn't show his true power.
As you can see in the books and movies, he even killed the Balrog, which is a VERY powerful being.
As powerful as Gandalf.
I dare to say that Gandalf's power is similar to Sauron's, as both are Maiar.
scifi.stackexchange.com/users/23863/undefined
Short answer:
Neither yes or no but kinda.
Adding to Avner Shahar-Kashtan's answer.
This is all off the top of my head
so I can't cite book/page
but Gandalf makes several comments and/or the narrative implies he has relied on the knowledge of others.
Though Gandalf is indeed Maiar and as such has a great deal of innate talent.
However it is clear that he learned much from Cirdan, Elrond and Galadriel aside from his own research and discussions with many human loremasters over the centuries.
Including specifically the casting of spells - cf.
his comment to Frodo before the Gates of Moria where he's trying to recall the password... that he once knew all the spells of elves, orcs, etc.
He speaks highly of Denethor's learning in LotR and seeks the council of Saruman, Elrond and Galadriel at numerous points in The Hobbit, LotR and The Silmarillion.
And even Saruman took centuries and expended great effort to learn what he knew.
Aside
(but related):
The Wizards as naturally "angelic" beings are in danger of being drawn into an inordinate passion for Middle Earth through their incarnation.
It is implied that the Blue Wizards have lost their way in the East, that Radagast has lost his purpose by being taken with the flora and fauna of Middle Earth, that Saruman's search for Ring Lore has made him weak to Sauron's sway of a promise of power.
scifi.stackexchange.com/users/21682/user23715
Wisest of the Maiar was Olórin.
He too dwelt in Lórien, but his ways took him often to the house of Nienna, and of her he learned pity and patience.
Dwelt in Lorien above means that Olorin was a Maiar OF Irmo, the "Lord and Master of Dreams, Visions, and Desires, and Creator of the Oloré Mallé, or Path of Dreams,"
BUT he ALSO learned pity and patience from Nienna.
There is also this about Olorin, clearly resembling Irmo: For though he loved the Elves, he walked among them unseen, or in form as one of them, and they did not know whence came the fair visions or the promptings of wisdom that he put into their hearts.
So, IF you accept that Nienna was a mentor to Olorin, as presented by Avner Shahar-Kashtan and Darth Satan then you have to accept that Irmo (Lorien) was also a mentor, only more so.
There is also some controversy as to whether Olorin was of the people of Manwe or Irmo.
In any event he had contact with Irmo, was called his counselor and lived in Lorien.
So, mentors for Olorin would be Manwe/Varda (maybe), Irmo/Este, and Nienna.
While Gandalf certainly continued to learn in Middle Earth, I don't consider anyone there to be a mentor:
Galadriel, Cirdan and Elrond would have recognized what he was, and he was already considered the wisest of the Maiar before he left Aman.
While Olorin was Maia and came into being with considerable gifts the quote shows that he LEARNED patience and pity from Nienna
, I take that to mean he was mentored.
scifi.stackexchange.com/users/40238/perry
Did Gandalf have a teacher/mentor?   If yes , who was his teacher/mentor?  If no , from where did he get his knowledge? How did he became so wise?   This question doesn't ask if he had a teacher to learn to become a wizard, though that may be implied. Gandalf is knowledgeable in things beyond just magic. Even a mentor may be considered a teacher, even if he is not taught about magic in specific.
Did Gandalf have a teacher/mentor?
scifi.stackexchange.com
<the-lord-of-the-rings><tolkiens-legendarium><gandalf>
scifi.stackexchange.com/questions/52055
scifi.stackexchange.com/users/23979/ReeCube
Gandalf is a divine being, one of the Maiar, whose very essence is wisdom. However, while Gandalf continued to learn in Middle Earth, he did not have a mentor. Gandalf is partially taught by Vala Nienna but has no mentor as such as his very essence is wisdom.
Gandalf is partially taught by Vala Nienna but has no mentor as such as his very essence is wisdom.