We are given the differential equation:
\[
\frac{dy}{dx} = \frac{y}{x}.
\]
This is a separable differential equation, so we can rewrite it as:
\[
\frac{dy}{y} = \frac{dx}{x}.
\]
Now, integrating both sides:
\[
\int \frac{1}{y} dy = \int \frac{1}{x} dx,
\]
\[
\ln |y| = \ln |x| + C.
\]
Exponentiating both sides:
\[
|y| = e^{\ln |x| + C} = |x| e^C.
\]
Thus, \( y = Cx \). Using the initial condition \( y(1) = 2 \), we get:
\[
2 = C(1) \quad \Rightarrow \quad C = 2.
\]
Therefore, the solution is \( y = 2x \).