3

I just installed MySQL, and by default the root user has no password. If I connect with this command:

mysql --port=3307 --host=127.0.0.1 -uroot -p

It asks me to enter a password, I just hit return, and it connects me. However, I want to make this part of a script, by piping a statement to it non-interactively, like this:

echo "$statement" | mysql --port=3307 --host=127.0.0.1 -uroot -p

But, when I actually do that, it still asks me for the password. How do I make it NOT ask for the password, and just not use one?

I tried removing the -p, and I get this message:

$ mysql --port=3307 --host=127.0.0.1 -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

I would expect there to be some sort of --nopassword argument, but I can't find one.

1
  • Did you resolve your problem? Commented Jul 1, 2015 at 14:51

2 Answers 2

1

Turns out the answer is actually to use the -p -- the long version allows you to set it to empty, like so:

mysql --port=3307 --host=127.0.0.1 -uroot --password=
1

If your MySQL client/server version is a 5.6.x a way to avoid the WARNING message or putting a password in command line, you can use the mysql_config_editor tools:

    mysql_config_editor set --login-path=local --host=localhost --user=username --password

Then you can use in your shell script:

    mysql --login-path=local  -e "statement"

Instead of:

    mysql -u $Username -p$Pass -e "statement"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.