MacPorts “selfupdate” error on OS X Mavericks

Recently I tried to update macports and got error:

$ sudo port install MySQL
...
Error: Error installing new MacPorts base: command execution failed
Please run `port -v selfupdate' for details.
Error: /opt/local/bin/port: port selfupdate failed: Error installing new MacPorts base: command execution failed

The fix is:

$ sudo xcode-select --install

Result:

The ports tree has been updated. To upgrade your installed ports, you should run
  port upgrade outdated