Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql connection whitespace after user flag

I have a question, What is the significance of the whitespace after the user flag -u inside a mysql connection string?

mysql -u myname -pmypass mydb

I mean to say, the above command works just fine, if I don't pass a whitespace after -u and just write the above command as below.

mysql -umyname -pmypass mydb

I tried searching for an explaination by using the following search terms.

  • mysql login whitespace after user flag
  • mysql connection console whitespace after user flag

I found the mention of whitespace after the password flag -p, Here. But the page no where talks about the whitespace after the user flag -u.

....there must be no space between -p or --password= and the password following it.

like image 750
Mohd Abdul Mujib Avatar asked Oct 24 '25 18:10

Mohd Abdul Mujib


1 Answers

The -p option takes an optional argument:

mysql --help --verbose
...
  -p, --password[=name]
  Password to use when connecting to server. If password is
  not given it's asked from the tty.

So, a command line that contains:

-p mydb

would be ambiguous ... does this means to:

  • Prompt the user for a password, and use the mydb database ?
  • Use the password mydb, and not set a default database ?

This is why the documentation insists on a particular rule for the password option: the value, if given, must be attached (no space).

For options that always take an argument, like -u, there are no special considerations, so the white space is not significant.

See the manual for a full documentation of command line options:

http://dev.mysql.com/doc/refman/5.7/en/command-line-options.html

like image 169
Marc Alff Avatar answered Oct 26 '25 09:10

Marc Alff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!