In order to increase salary in a company, you need to get promoted. If u are in a company where there is no career path, then getting out ASAP, 2 years, make sense.
There is always a market rate for the salary for every role. If your current salary is already at that rate (upper range). Then you need to hop to a higher position that come with more responsibilities.
If your salary is already at the upper range, then is alright to stay abit longer, see if there is a chance for promotion.
However, if the current salary is good enough and the job is relatively easy. Then may consider stay long term. Because every job hop is a risk, you may encounter toxic culture or boss from hell.