MySQL Monitor Program Options

The monitor program can take several parameters; the ones you’ll need most frequently are:

host

The host the server is running on; you can leave this out if the server is running on the same host as the client (localhost).

user

The username to use when connecting to the MySQL server. This bears no relation to the username the server is running under, or to your Linux or Mac OS X username. If you don’t provide a username with this option, the monitor uses a default value; this default username is your machine account name on a Linux or Mac OS X system, and ODBC on a Windows system.

password

The password of this user. If you don’t provide the password parameter, no password is supplied to the server. This is fine if there is no password stored for that user, but if the user does have a password, the connection will fail:

$ mysql --user=the_username
ERROR 1045 (28000): Access denied for user 'the_username'@'localhost'
  (using password: NO)

If you include the password option but don’t specify a password, the client will prompt you for a password after you press the Enter key. If the user has no password, pressing the Enter key will work; otherwise, the connection will fail again:

$ mysql --user=the_username --password
Enter password:
ERROR 1045 (28000): Access denied for user 'the_username'@'localhost'
  (using password: NO)

If you provide an incorrect password, or you don’t have permission to access a specified database, MySQL will note this in the error message: ...

Get Learning MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.