Has Krishna actually said this in Mahabharata ?
Yes, Bhagavan has said this in the Mahabharata to Yudhishthira. After the Pandavas were exiled owing to their loss due to gambling, Bhagavan teaches them about the vices of gambling. It is during this conversation that he says the concerned line, which is as follows:-
स्त्रियोऽक्षा मृगया पानमेतत् कामसमुत्थितम्। दुःखं चतुष्टयं प्रोक्तं यैर्वरो भ्रश्यते श्रियः॥७॥
Sex, gambling, hunting and drinking, these four sorrows (vices) are spoken of as originating from pleasure. Owing to these a person’s wealth and fame (Shri) are destroyed.
-Mahabharata Vana Parva Chapter 13, verse 7
It it noteworthy to compare this with the vices that lead to destruction of a king, as mentioned in the Dharmashastra:
मृगयाऽक्षो दिवास्वप्नः परिवादः स्त्रियो मदः। तौर्यत्रिकं वृथाट्या च कामजो दशको गणः॥४७॥
Hunting, dice, sleeping during the day, censoriousness, sex, intoxication, musical triad and listless wandering constitute the ten-fold set arising from the love of pleasure.
Bhagavan is basically giving knowledge of the dharmashastra to the Pandavas.