Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to write a bash command for accessing a remote MySQL server?

If I try

    mysql -host -port 3306 -u root -p 1234

it prompts the password and after I type in the password it considers 1234 as a database name and claims that there's no such database.

share|improve this question
up vote 2 down vote accepted

Try the "--pasword=" syntax, instead. In fact, use the "--database=" syntax, as well. In scripts, I prefer the explicit, long-form options, as they're more self-documenting.

share|improve this answer

As Geoff Fritz said, you can use the --password= syntax, but that's insecure. You're better off using MySQL configuration files, like this:


Name this file .my.cnf, put it in your home directory, and give it 600 permissions so that no one can you but read it. See the MySQL reference manual.

share|improve this answer

Just remove the space between the "-p" and the password. i.e. -p1234

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.