The prevalence of antibiotic resistance in urinary tract infections (UTIs) often renders the prescribed antimicrobial treatment ineffective, highlighting the need for personalized prediction of resistance at time of care. Here, crossing a 10-year longitudinal dataset of over 700,000 community-acquired UTIs with over 6,000,000 personally-linked records of antibiotic purchases, we show that the resistance profile of infections can be predicted based on patient-specific demographics and clinical history. Age, gender, and retirement home residence had strong, yet differential and even non-monotonic, associations with resistance to different antibiotics. Resistance profiles were also associated with the patient's records of past urine samples and antibiotic usage, with these associations persisting for months and even longer than a year. Drug usage selected specifically for its own cognate resistance, which led indirectly, through genetic linkage, also to resistance to other, even mechanistically unrelated, drugs. Applying machine learning models, these association patterns allowed good personalized predictions of resistance, which could inform and better optimize empirical prescription of antibiotics.