How to derive the closed-form formula for the square sum through integration? I know that the closed-form of $\sum_{i=1}^n i^2$ is $n(n+1)(2n+1)/6$.
But how to derive the formula through integration? My attempt is
$$
\sum_{i=1}^n i = \frac{n^2+n}{2}\\
\frac{1}{2}\sum_{i=1}^n i^2 = \frac{n^3}{6}+\frac{n^2}{4}\\
\sum_{i=1}^n i^2 = \frac{n^3}{3}+\frac{n^2}{2}\\
$$
My result is obviously not true, but why? Is there a way to derive the formula through integration?
Thank you for your effort!
 A: The follwing method involves integrals. It may not be the answer you're looking for though.
Let $ n\in\mathbb{N} $.
Notice that, forall $ k\in\mathbb{N}^{*} $, we have  $ \int_{k-1}^{k}{x^{2}\,\mathrm{d}x}=k^{2}-k+\frac{1}{3} $, thus : \begin{aligned}k^{2}&=k-\frac{1}{3}+\int_{k-1}^{k}{x^{2}\,\mathrm{d}x}\\ \Longrightarrow\sum_{k=1}^{n}{k^{2}}&=\sum_{k=1}^{n}{k}-\frac{n}{3}+\int_{0}^{n}{x^{2}\,\mathrm{d}x}\\ &=\frac{n\left(n+1\right)}{2}-\frac{n}{3}+\frac{n^{3}}{3}\\ \sum_{k=1}^{n}{k^{2}}&=\frac{n\left(n+1\right)\left(2n+1\right)}{6}\end{aligned}
A: 
The continuous function $\frac{n(n+1)}{2}$ is not the same as the discrete sum, as shown in the image.

Warning: the steps below are not justified, but they happen to work.
How about differentiating $\sum_{i=1}^n i^3$ ?
$$\sum_{i=1}^n i^3 = \left(\frac{1}{2}n(n+1) \right)^2$$
$$\Rightarrow \frac{d}{dn} \sum_{i=1}^n i^3 = \frac{1}{4}\left((2n+1)(n)(n+1)+n(n+1)(2n+1) \right) \tag{product rule}$$
$$\Rightarrow 3 \sum_{i=1}^n i^2 = \frac{1}{2}(n)(n+1)(2n+1)$$
$$\Rightarrow\sum_{i=1}^n i^2 = \frac{1}{6}(n)(n+1)(2n+1)$$
as if by magic.
