This has been asked & answered before, albeit not with the specific consideration of a magic-user using a spell attack. So please read the linked question, and I'll add information more applicable to your special case.
Yes, the monster gets an opportunity attack; as with any character attempting a similar kind of advance -> act -> retreat
.
As for the 5 foot move part of your question: that is an earlier edition rule and no longer appears in 5th edition. So you provoke an opportunity attack as soon as you leave the creature's reach; and in most cases 5 foot is just beyond reach.
And yes, the Disengage action would be required to avoid an opportunity attack, but typically defeats the purpose because it takes up the action that would be used to to cast the spell in the first place.
However, many classes do gain abilities at higher levels that enable them to advance -> act -> retreat
without provoking an opportunity attack. As an example, Wizards have the level 2 spell Misty Step.
teleport (which doesn't provoke an opportunity attack) to an unoccupied space up to 30 feet that you can see.
This spell is cast as a bonus action. But it does have the restriction that your attack spell must be a cantrip with a casting time of 1 action.
- So dig a little deeper into what your class can do.
- Or consider taking low levels in another class (E.g. Level 2 Monk can spend ki points to disengage as a bonus action.)
- And take a look at what feats can help you. (E.g. The Mobile feat is applicable because it doesn't differentiate whether the melee attack is a weapon or spell attack.)
In the right "critical moment" advance -> act -> retreat
can have spectacular benefits. However, do bear in mind that trying too hard to avoid the opportunity attack in that situation will be "expensive": In the sense that it often takes the place of abilities that are more cohesive with the rest of your class. And it may use up resources such as: bonus action for a round, spell slots; which might have been put to better use in another way.
Side Notes
A few things things to bear in mind:
- If a creature has already used its reaction for the round, it is (in most cases) unable to make an opportunity attack.
- If a creature has in some way been incapacitated, it is unable to use actions/reactions and so cannot make opportunity attacks.
- If a creature has disadvantage on attack rolls, you're more likely to retreat safely even if it does take an opportunity attack.
- A bit of teamwork can also help: An ally can use an attack action to shove an enemy (or even shove you) out of its reach.