mysql is prompting for password even though my password is empty

Viewed 50649

I installed mysql on ubuntu server and did not specify password. When I do

mysql -u root -p 

it prompts for password and without providing any input I just hit enter and it works.

Now I need to perform some operation on the database using cron job. My cron job does not work because mysql prompts for a password. I tried doing

mysql -u root -p'' my_database

but that did not work either.

Any suggestion?

7 Answers

For passing the password in the command use -p$PASSWORD. In the following example, user/password is root/root:

mysql -proot -D my-db -u root -h 127.0.0.1 -e "select * from my_table"

IMPORTANT: notice that there is no space between -p and the password in -proot

Related