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

If I try

    mysql -host 10.1.1.20 -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.

link|improve this question

68% accept rate
feedback

3 Answers

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.

link|improve this answer
feedback

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

[client]
password=your_pass

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.

link|improve this answer
feedback

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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