Reputation: 38460
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?
Upvotes: 36
Views: 61114
Reputation: 1
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
Upvotes: 1
Reputation: 7035
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
Upvotes: 9
Reputation: 2845
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.
Upvotes: 1
Reputation: 385194
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!
Upvotes: 15
Reputation: 33592
Mysql's "root" account should have a password; otherwise anyone with an account on your machine has full access to the database.
If you want more sane authentication options, I recommend Postgres.
Upvotes: 0
Reputation: 7576
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.
Upvotes: 31
Reputation: 10366
Why don't you specify a password for root? For security reasons and your script would work.
Upvotes: 0