Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

When entering a new password for the root account in mysql I accidentally did this:

   mysqladmin -u root -p password 'somepassword 

Where you can see I missed the second quote. and I got something like this .

    >

So I entered " ' " to finish the statement

Now the password doesn't work. I understand I can start the mysql server with an init file and reset the password but I was wondering if anyone knows what the above translates to. Is it a new line??

Edit:
I'm not asking how to reset or recover the password (I know how to do that but I'm trying to avoid restarting the service). The question is: is possible or not to enter a password here if this typo is made.

share|improve this question
1  
I know this doesn't answer your question, but you should never be typing the password in the command line directly anyway. This stores a plain text copy of your password in the .bash_history file for anyone to see. Always use "mysqladmin -u root -p" and then wait for the password prompt. –  Tony Maro Mar 13 at 16:18
    
Indeed best practice would have me log in with the mysql client and make the changes there. Thanks for the suggestion. –  Chris Jones Mar 13 at 17:27

3 Answers 3

Then just reset your MySQL password. This is how I do it in Ubuntu 12.04. Should work similarly in other setups. It’s considered an insecure way of reseting a MySQL password since you do have to launch MySQL in an open/non-credential based mode to do this. But if you do it & then restart MySQL normally, you should be fine.

First, I stop the MySQL service:

sudo service mysql stop

Then I restart it with the --skip-grant-tables flag:

sudo mysqld --skip-grant-tables &

Now you can login without a password like so:

mysql -u root mysql

And then I run the following query to reset the password. Note you should change the value of YOURNEWPASSWORD to whatever password you actually want to use:

UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE user='root'; FLUSH PRIVILEGES; exit;

Now that that is done, exit out of MySQL and restart the daemon like so:

sudo service mysql restart

If somehow that doesn’t work, use a killall to kill all instances of mysqld:

killall mysqld

And then start the MySQL service again as you normally would:

sudo service mysql start

The new password should be set & you’re good to go.

share|improve this answer

If you know *exactly what you typed then you can log in with that value - but you need to specify it on the command line rather than via an ini file or the password pro,pt (where newline is interpreted as the end of the input).

e.g. mysqladmin -u root -p"somepassword\n\n\n" password 'newpassword'

If you can't recreate the value you typed in previously then you'll need to go down the different ini file route.

share|improve this answer
    
Great idea sadly it didn't work. Looks like im off to schedule a maintenance window :( –  Chris Jones Mar 13 at 14:42

Shot in the dark here, but it looks like your password has an embedded newline character now. Try adding \n to the end of your password string and see if it works, or otherwise inserting the newline/linefeed control character at the end of your password (depends on terminal.)

It also just occurred to me. Can you just repeat the same thing again? e.g.

mysqladmin -u root -p 'password RET
>' whatever-you-want-to-do RET

Obviously a little cumbersome. Don't have an install to test on, or I'd have done so, but worth a shot.

Note: I feel like this has happened to me before.

share|improve this answer
1  
Thanks for the attempt. Great idea. Looks like im off to schedule a maintenance window. Thanks again. The note was especially nice –  Chris Jones Mar 13 at 14:43
    
Ha, you're welcome! Stuff like this... "it's all in the game." –  Sam Halicke Mar 13 at 16:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.