Which one of the following is grammatically correct?
It would be better if you drink all the water.
It would be better if you drank all the water.
The question is, obviously, about the use of the past tense.
The second sentence is correct, but don't confuse its meaning.
The structure is past tense, but the meaning isn't past at all. This means opposite to the real situation or, in other cases, imaginary.
Both sentences above mean real possibility.
Because of the differences in application, we don't usually mix up the clauses of the Conditional (If).
It is clear that the latter sentence "It would be better if you drank all the water" is referred to an imagined situation (if you drank all the water) and the possible result of this situation (It would be better.)
In other terms, your second sentence is a "conditional sentence."
In this light, you have to follow the rules governing the associated grammatical structures, which in this case are referred to the second conditional.
We use the second conditional to talk about the possible result of an imagined situation in the present or future.
The form of the second conditional is the following:
That said, your second sentence is correct, while the first one does not follow the above rules.
However, if you rewrite the first sentence in this way "It will be better if you drink all the water", it works.
"It will be better if you drink all the water" is referred to future result (It will be better) of an imagined future situation (if you drink all the water), when we believe the imagined situation is quite likely.
So, replacing "would" with "will," your first sentence is still a conditional sentence which structure is named first conditional:
Reference: English Grammar Today, Cambridge.
In a sentence like that, the verb in the ‘if’ clause needs to be in the past tense: It would be better if you drank all the water. You use the present tense when the main clause consists of ‘will’ followed by ‘be’: It will be better if you drink all the water.