Go to Settings → Privacy and ask for an export. The site gathers your account details, your posts, your messages and everything else attached to you, and tells you when the file is ready to download.
It is built in the background rather than while you wait, because on a long-standing account it is a lot of material.
The same screen is where you ask for your account to be removed. That is a separate and much more serious action — see the article on deleting your account before pressing it.