Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am constantly get the following error message:

1045 Cannot log in to the MySQL server

I have tried the following:

  1. sudo service mysql stop (Went fine)

  2. sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking & (Went fine)

  3. mysql -u root (Went fine)

  4. FLUSH PRIVILEGES; (Went fine)

  5. SET PASSWORD FOR root@'localhost' = PASSWORD('password'); (I get the following error:)

    ERROR 1133 (42000): Can't find any matching row in the user table
    mysql> select User from mysql.user;
    | User             |
    | linux            |
    | root             |
    | debian-sys-maint |
    3 rows in set (0.00 sec)
share|improve this question
where do you get the error? in your log? in your app? in your website? in you terminal? – Nanne Jan 10 '13 at 11:10
In my terminal, after login in mysql – Francesco Jan 10 '13 at 11:46
So you type a command? what command? please add this information t your question. – Nanne Jan 10 '13 at 12:20
As per my description above, I am unable to login into the mysql server, so I am trying to modify the password. when I type the folloing command: SET PASSWORD FOR root@'localhost' = PASSWORD('password'); get the following error: ERROR 1133 (42000): Can't find any matching row in the user table Therefore I am unable to modify the password and to login into phpmyadmin page. Hope is that clear. – Francesco Jan 10 '13 at 12:45
Anyone ?? Issue still exist! – Francesco Jan 18 '13 at 11:56

When you do

SET PASSWORD FOR root@'localhost' = PASSWORD('password'); 

you are updating the password for a user that has name root and location localhost. From your result of your user table I conclude that there is NO such line. There seems to be a line with root and, so therefore you probably need this line.

    SET PASSWORD FOR root@'' = PASSWORD('password'); 

Please try and understand what the difference between the two lines is, and why this should be done instead of the former: I hope this helps you see what was wrong and why you should do this, as it might be not spot-on: the comment-additions would be much easier to read if they are in the question, and formatted correctly :D

share|improve this answer
Thanks, I would really like to put in here nicely and formatted, but this field does not allow me to do it...btw, I am getting this output after I run [SET PASSWORD FOR root@'' = PASSWORD('password');]: No connection. Trying to reconnect... ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) ERROR: Can't connect to the server – Francesco Jan 22 '13 at 15:52
That's why I mentioned you should put extra information in your question (and using the buttons and the preview there, you can achieve better formatting :) ) – Nanne Jan 22 '13 at 16:03
by the way: I think you might have a different problem then the one you posted here: the set-up of your system isn't correct, and you have googled some sort of solution that is not necessarily the best. This is called the xy problem (see: ). It's hardish to help you like this, so I don't know how much further we can get ... – Nanne Jan 22 '13 at 16:05
Thanks for the 'nice' scenario xy, the thing is that I did not touch anything, I had a clean install of mysql, apache and php and I cannot login. Now you are telling me that "the set-up of your system isn't correct" ?? I dont get this!! I post in here to find help as it might be something else and you guys are the one who can (suppose to) help !! By the way: Nice for the other passer-bys! – Francesco Jan 22 '13 at 16:36
That's exactly what I mean: your problem seems to be "I installed mysql, and now I get this error." You did not specify where you got this, what you did, but you did specify your sollution, that ended in another error. I am trying to help you fix this error (by telling you that you should change that last line to include a user that exists), but I think the initial problem should have been the focus. Anyway, I have done my best to help you but I'm not "supposed to" help, I was just trying to be nice. good luck to you. – Nanne Jan 23 '13 at 8:04

Your Answer


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.