Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

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:

[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.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

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.