How do I get past this MySQL error installing Craft 3 using CLI
This is all very specific to the box you're using, and how it's configured. I realize Scotch Box is a historically popular setup; you might also consider Homestead as it is geared specifically for PHP development.

Anyway, according to the Scotch Box docs the setup should be:

Database Host: localhost
Database User: root
Database Password: root

Which I assume you're doing in the second example? You are also running all of this from inside of the box, yes?