mysql is prompting for password even though my password is empty

56.8k Views Asked by At

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?

8

There are 8 best solutions below

4
On BEST ANSWER

Try not asking mysql to prompt for the password, 'mysql -u myuser'. I would suggest you create an account with only the required privileges to do this. Also limit its access to localhost. Put a password on root.

0
On

A password prompt also occurred even though the password apple was given as shown below:

mysql -u john -p apple

And:

mysql -u john --password admin

Then, the error below occurs:

ERROR 1044 (42000): Access denied for user 'john'@'%' to database 'admin'

So, I changed -p apple to -papple and --password admin to --password=admin respectively as shown below, then I could log in to MySQL:

mysql -u john -papple

And:

mysql -u john --password=apple
1
On

Check MySQL Documentation for how to reset your password, since I found no way to enter a password either. You could use the following: http://dev.mysql.com/doc/mysql-windows-excerpt/5.0/en/resetting-permissions-windows.html Which states that you have to create a file with the following query:

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;

And then start up mysqld service with the --init-file parameter (see the documentation for more information about this). This should reset your root password.

1
On

Go like this mysql -u root --password="" dbname

0
On

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

mysql -u root -p

-p brings up the password prompt. If you do not have a password, then you do not want to do that.

Just write:

mysql -u root

For the love of god, get a password on that account!

0
On

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

2
On

Why don't you specify a password for root? For security reasons and your script would work.

0
On

Mysql's "root" account should have a password; otherwise anyone with an account on your machine has full access to the database.

  1. Set a password (e.g. with SET PASSWORD)
  2. Add the password to ~/.my.cnf

If you want more sane authentication options, I recommend Postgres.