tags:

views:

27

answers:

3

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?

+1  A: 

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

luckytaxi
I agree, just actually set a root password and then the specified code should work fine.
Cole
Better yet, OP should create a non-root user and give access for new user to the DB in question.
luckytaxi
+3  A: 

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.

BillThor
+1, This is technically the answer the user is looking for. To not have MySQL prompt for a password, don't set `-p`.
wuputah
wuputah you are right. Don't ask me to set password when I don't want to set password.
Nadal
I am suggesting you use good security. Running root without a password is high risk. At least limit access to the local system. Best practice for no password accounts is least access.
BillThor
A: 

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.

tc.