You can get to Slovakia by an international train from all its neighbouring countries.
Search for train connection at Slovakrail.sk.
You can get international train tickets at RailEurope.
The Czech Republic:
There are express trains running between Prague and Bratislava 8 times a day (204 km, 2 hours 45 minutes.). From Prague you can take a direct train to Tatras, Košice (4 times a day, 700 km, 8 – 10 hours), Žilina (14 times a day, 450 km, 5 – 5 hours 30 minutes) and Banská Bystrica (2 times a day, 550 km, 7 – 8 hours). If you are not in a hurry, you can also use romantic local connection through mountain farming area of Myjava (Veselí nad Moravou – Nové Mesto nad Váhom). Passenger train also run through Vlársky priesmyk, Horní Lideč, or Mosty u Jablunkova.
You can now also reach Slovakia by the yellow RegioJet trains that run every day on the route Prague – Ostrava – Žilina – Košice and back (9 hours).
From Warsaw to Bratislava there is an express train running 2 times a day (615 km, 7 – 9 hours), from Krakow 1 time a day (410 km, 7 hours 41 minutes). Express trains from Poland to Slovakia run through the Czech Republic. There is only one passenger train you can take between Poland and Slovakia, in Kysuce (Zwardoň – Žilina). Passenger transport on other rail tracks is currently suspended.
There is a train running from Budapest to Bratislava 8 times a day (204 km, 2 hours 45 min.), to Košice 2 times a day (270 km, 3 hours 30 minutes).
Trains between Vienna (Wien Hbf) and Bratislava (Bratislava Main Station and Bratislava Petržalka) are running 2 times an hour (70 km, 1 hour).
From Berlin to Bratislava there is a direct train 4 times a day (800 km, 9 hours), from Hamburg 1 time a day (1,150 km, 11.5 hours).
Once a day you can get to Bratislava by a direct train from Moscow (40 hours) and from Kiev (28 hours).