Proving this relation is an equivalence For $\sim$ defined on $\mathbb{Z}$ by
$$x\sim y \iff m^2 x = n^2 y$$
for some positive integers $m,n$.  
I'm not sure if the transitive property is properly proved here..  
Suppose $x,y,z \in \mathbb{Z}$ with $x \sim y$ and $y \sim z$.  
Then, for some positive integers $m,n,k,l$,
$$m^2 x = n^2 y \qquad \text{and} \qquad k^2 y = l^2 z$$  
$$y = \frac{l^2}{k^2}z$$
so $$m^2 x = \frac{n^2 l^2}{k^2}z$$
but the coefficient of $z$ is not necessarily an integer....
Am I supposed to set $k:=1$ or something?
 A: $$m^2 x = n^2 y \qquad \text{and} \qquad k^2 y = l^2 z$$ 
$$k^2(m^2x) = k^2(n^2y)=n^2(k^2y)=n^2(l^2z)$$
That is $$(km)^2x=(nl)^2z$$
Note that $km$ and $nl$ are both positive integer.
Hence $x \sim z$.
A: Generally let $\ x\sim y \iff ax = by\,$ for some $\,a,b\in M,\,$
where $M\subset \Bbb C$  is closed under $\rm\color{#0a0}{multiplication}$. Then
$\qquad\qquad\begin{align} &\ \ \overbrace{ax =\ \  by}^{\Large x\ \sim\ y}\\
\Rightarrow\ &cax = \color{#c00}{cb}y\\
\phantom{1}  
\end{align}\ $ 
$\begin{align} &\overbrace{\ \,cy =\  dz}^{\Large y\ \sim\ z}\\
&\color{#c00}{bc}y =  bdz\,\ \Rightarrow\ \underbrace{\color{#0a0}{ca}x = \color{#0a0}{bd} z}_{\Large x\ \sim\ z}\end{align}$
where $\,\color{#0a0}{ca,bd} \in M$ since $M$ is closed under $\rm\color{#0a0}{multiplication}$. Thus $\,\sim\,$ is transitive.

Remark $ $ We multiplied the 1st equation by $\,\color{#c00}c\,$ and the 2nd by $\,\color{#c00}b\,$ in order to unify (or overlap) the coefficients of $\,y,\,$ so that we could deduce transitivity of $\,\sim\,$ via transitivity of $\,=\,$.  
Such unification or overlapping is ubiquitous method of deriving consequences of equations and axioms - often employed in term-rewriting and equational / axiomatic inference systems. See this answer for further discussion.
