For example, I download all the content of Academia@SE, later analysis it in a data mining paper, and submit the paper in the end. Is it OK to do so? Do I have to ask the permission from the administrator of the website? And does he or she have rights to forbid my academic use? Thank you.
Your University may have an Institutional Review Board (IRB) that reviews how you conduct experiments. This board may be known by various names (Ethics Committee, Experiment Review Board, Human Subjects Research, etc.) but they are generally the ones that you would go to to consult about whether what you are doing is within the scope of ethical behavior and good treatment of human subjects data.
As StackOverflow and associated StackExchange repository data is available under Creative Commons Attribution Share-Alike (as @piotr_migdal linked above) and is publicly available, your IRB will probably tell you, "It's fine" and not require review. However, it depends on the IRB and the institution and the nature of the data.
There are entire research disciplines built on scraping web sites, software repositories, and social media, so don't feel bad for doing it.
Disclaimer: I am not a lawyer. If you are seriously concerned about this issue, you should consult one; your institution probably has intellectual property lawyers on staff.
There is a general principle that "you can't copyright facts". Wherever you get your data set, you probably can legally publish any analysis of that data, without requiring anyone's permission. However, you may not be able to legally reproduce the data itself.
Of course, by standard academic ethics, you must properly cite and attribute the source of the data. And if you can't guarantee that the data will remain accessible, it could affect the reproducibility of your results and hence the quality of your paper.
I believe you can do it with StackOverflow data, as long as you cite/attribute it properly. This article affirms it. However, I do not know whether this can be extended to the rest of StackExchange. A question to the mods or to the support team might help you clarify.