This post show you how you can migrate data from a Drupal 5 database to a Drupal 7. It might be some easier ways using some modules for export and import, but this is how you can make it the programmatically way. This is NOT a ready to go script this is more or less a copy of a script I just made, you have to code a bit to make it work.
In order to rebuild the menu in Drupal 6 you have to go to admin/build/modules, but you don't have to submit it.
In Drupal 5 you just need to empty the cache table by TRUNCATE cache_menu;