Search the MySQL manual:

4.2.8 Connecting to the MySQL Server

MySQL client programs generally require that you specify connection parameters when you want to access a MySQL server: the host you want to connect to, your user name, and your password. For example, the mysql client can be started like this (optional arguments are enclosed between `[' and `]'):

shell> mysql [-h host_name] [-u user_name] [-pyour_pass]

Alternate forms of the -h, -u, and -p options are --host=host_name, --user=user_name, and --password=your_pass. Note that there is no space between -p or --password= and the password following it.

Note: Specifying a password on the command-line is not secure! Any user on your system may then find out your password by typing a command like: ps auxww. See section 4.1.2 `my.cnf' Option Files.

mysql uses default values for connection parameters that are missing from the command-line:

Thus, for a Unix user joe, the following commands are equivalent:

shell> mysql -h localhost -u joe
shell> mysql -h localhost
shell> mysql -u joe
shell> mysql

Other MySQL clients behave similarly.

On Unix systems, you can specify different default values to be used when you make a connection, so that you need not enter them on the command-line each time you invoke a client program. This can be done in a couple of ways:

User Comments

Posted by Lars Aronsson on Saturday June 8 2002, @10:11am[Delete] [Edit]

In several places, the MySQL documentation talks
about the "-ppassword" option to the mysql
command. However, the default use under Unix/Linux
seems to be that "-p" will cause mysql prompt for
a password, while leaving out "-p" will cause
mysql to attempt accessing the database without
using any password at all.

Posted by Nancy Ging on Thursday August 22 2002, @3:23pm[Delete] [Edit]

This is also true with the Windows NT/2K version.
The password will not be requested if -p is omitted.

Posted by Jim M on Friday April 11 2003, @5:28am[Delete] [Edit]

As root I ran the included mysql_secure_installation program this set the necessary permssions for me to have it require a password by default.

Posted by Kevin Mitchell on Wednesday June 11 2003, @1:56pm[Delete] [Edit]

Below is an extract of my documentation which clearly states that you only be prompted for the password if "-p" is included:

Exiting and Reconnecting to the MySQL Monitor
In order to test the new password, exit the MySQL database using the following command:

mysql>\q

This will return you to the system shell. Now log back into the monitor, this time using the following command:

%>mysql -u root -p

Doing so will result in a prompt for the root user password, as follows:

Enter password:

Go ahead and enter the password supplied within the update command that was used to set the root password. Assuming it is entered correctly, the standard MySQL greeting will appear, and root will be connected to the MySQL server once again.

Add your own comment.