It's what I'm doing right now: I started a PhD in computer security after 7 years working as a software engineer in the industry. All of that in Europe.

The answer to your questions is -of course- it depends.

As somebody said in the thread, not all PhD are created equals. The "structure, focus and community" you will get from a PhD will vary greatly depending on your topic / lab / team / advisors.

For me, it mainly brought two big positives and two culture shocks.

- First big positive, while a PhD in itself is not super prestigious, a PhD in a topic in hot demand is. I wanted to transition my career from a software engineer with light exposure to security problems to fully-fledged security expert; even if I'm not done yet, this part seems to go as planned.

- Second big positive, if you love the topic you'll deeply enjoy most of the days there, especially if you have had a career before: you probably have a better BS detector and more down-to-earth aspirations than a brand new master student, and be more likely to work as equals with your advisors. I love my typical days: I have a private office and basically have free reign on how to move my research forward in basically any direction I see fit. I should add that writing and speaking publicly is also a big part (40-50%) of doing a PhD, but it is something I happen to love personally. If you hate writing, don't do it!

- First culture shock was how most PhD students are set to work alone, with weekly discussion with their advisors only and next to no collaboration with other PhD students. Coming from hectic teams in the software industry where we would collaborate daily if not hourly, the lonesomeness of the PhD was striking at first, albeit not unappreciated (No urgent emails ? No pagers at 3am ? No manager interrupting my train of thoughts 3 times in the afternoon ?). I do think the best projects are born from collaboration and if you can find a team with exciting research goals collaborating together to reach them, this can be a PhD holy grail. While I love that I can go down a rabbit hole all by myself without asking for permission, when I'm stuck at the bottom, I'm stuck alone, and this was new to me. This requires discipline because when you're given a lot of leeway, your greatest enemy becomes yourself.

- Second culture shock, at times public research feels closer to prestige-based industry (like entertainment) than engineering. There are a few superstars and a lot of nobodies; You compete with everyone worldwide and everybody's CV is public; You'll go from feeling bad because somebody's research is ten times better than yours, then facepalm because somebody else's research is ten times worse than yours. There are not a lot of correlation between the quality of your work, your reputation, and your salary.

- I also should add that if you have a family, a PhD program may strongly encourage or even require you spend a few months abroad in other universities. For me it was not possible (raising a young child) so I made it clear with my advisors upfront and it went well. But overall it is very difficult moving forward in academia (which I don't aim to) without moving a lot geographically, which can be tricky if you have a significant other and / or children.

- Regarding the specific mathematics part of your question, I feel your struggle as my maths were super rusty going in. While a great joy of a PhD is that you can take a few hours / days to dive deep into a mathematical concept you don't understand, you do not have enough time to enroll into a full master in mathematics either. So you still have to pick your battle there.

I hope that helps. Good luck!