Some countries require visas in advance, most do not, this also depends on your nationality. The visas are generally free, unless you require an extension for your stay. Upon entry into a new country, you may need to pay the immigration, customs, health and quarantine officers.
Upon leaving, a departure tax and varying amounts based on the size and weight of your vessel might also need to be paid. These fees can sometimes total up to 200US$. We find Noonsite to be a good up-to-date ressource for country-specific information on fees.