If you look at the PHP function for establishing a MySQL connection (which one it is depends on which extension you're using - the abstraction-layer PDO one, the MySQL-specific MySQLi one, or the deprecated MySQL one), you will see how they each deal with user login credentials.
For comparison with something more familiar, see also the corresponding functions for Oracle: [man]PDO-OCI.connection[/man], [man]oci_connect[/man].
If you want to communicate with the MySQL DBMS via the CLI, then it's a matter of running the MySQL client, which after locating the database server, asks you to enter your username and password. But if that's what you're doing and you're having trouble, then PHP isn't involved and you'd be better served asking in a MySQL forum.