Integrating $\int \frac1{x} dx$ by parts yields $\int\frac1{x}dx=\int\frac1{x}dx-1$. Where's the mistake? I can't understand where the mistake in the following steps is:
$$\int \frac{1}{x}dx = \int x  \frac{1}{x^2}dx = -\int x (-\frac{1}{x^2})dx = -\int x(\frac{1}{x})'dx = -x\frac{1}{x} + \int \frac{1}{x}dx = -1 + \int \frac{1}{x}dx$$
So: $$\int \frac{1}{x}dx = \int \frac{1}{x}dx -1$$

Also: Why is it that the integral of this function is $\ln x$? How did people conclude that?
 A: $\int\frac{1}{x}dx$ denotes the set of all antiderivatives of $\frac{1}{x}$. You've shown a function $f$ is such antiderivative iff $f-1$ is too. You need another method to show it's a logarithm. You can note for example that$$\frac{dy}{dx}=\frac1x\implies\frac{dx}{dy}=x\implies x\propto\exp y\implies y=\ln x+C.$$(Due to the discontinuity at $x=0$, $C$ in this context is locally constant. For example, if $x$ is a real variable, we can choose $y-\ln|x|$ to have a $\operatorname{sign}x$-dependent value that's otherwise constant.)
A: The reason for "contradictory looking" result is because you are trying to estimate an indefinite integral. An indefinite integral such as 
$$
\int \frac1x dx
$$
gives a set of answers. So 
$$
\int \frac1x dx = \{f: f(x) = \log x + a \text{ where } a \in \mathbb{R} \}
$$
So the equality you got is actually a set equality. That is 
$$
\{f: f(x) = \log x + a \text{ where } a \in \mathbb{R} \} - 1 = \{f: f(x) = \log x + a \text{ where } a \in \mathbb{R} \}
$$
and there is nothing wrong mathematically. 
Your steps aren't wrong, they just do not account for the set equality that you are showing. 
The reason why 
$$
\int \frac1x dx = \log x + a
$$
is mainly due to the definition of exponential function $\exp$ and its relation to the logarithm $\log$.
