You can buy train tickets on-line, installing an app, at the counter, at automatic ticket machines and at travel agencies displaying the railway companies logos. Agencies can add a small fee on top of the price displayed online, ask about it.
Trenitalia's Regionale trains tickets can be purchased also at many Tobacconist shops.
Discounted tickets for high speed and long distance trains aren't available on the departure day. You can always get tickets at the last second, trains do not sell out, but you'll pay the full on-day prices.
Full, walk-up prices are always displayed on official sites, they are called BASE on trenitalia.com/tcom-en and FLEXi on italotreno.it/en. You can't pay more than BASE and FLEX.
Discounted tickets can't be changed or refunded.
From Milan to Riomaggiore I'd take a Trenitalia direct train to Monterosso (3 hours if I'm not wrong) followed by a local to Riomaggiore. A little slower than other solutions, but only one change.
Florence, Rome, Venice and Milan are all served by high speed trains.
Think at when you should stay in Florence, just after the Cinque Terre or while going back to northern Italy. There are direct Rome-Venice trains that take less than 4 hours.