I'm trying to install LAMP on ubuntu 16.04. I had everything installed, but accidentally locked myself out of LAMP trying to get phpmyadmin working, I get Access denied for user 'root'@'localhost' with whatever I try.

I thought the easiest solution would be to uninstall all packages I installed to get LAMP working. I used sudo apt-get purge to uninstall all packages I installed. Now I'm installing all packages again but I get the same error when trying to install mysql. I try: sudo mysql_secure_installation and it asks me for the password for root. I tried leaving it empty, giving the passwords I think I set for root, but everything just returns the access denied message.

Trying to get into mysql with mysql -u root -p always returns the access denied message, I tried a solution by creating a file with CREATE USER 'root'@'localhost' IDENTIFIED BY '<password>'; and running sudo mysqld_safe --init-file=<path_to_file> but I still receive the access denied messages.

I'm thinking there is a file somewhere with the information, maybe the password, it needs. I tried a lot of other solutions too but nothing seems to work.

EDIT: I investigated further, and I tried starting the mysql service with the --skip-grant-tables flag to stop checking user privs. When I run mysql -u root it still tells me ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO). I think the problem hasn't to do with my password, but something else.

  • The pwd for sudo should the same as your regular account's password if you are in the sudo group. Have you tried that one? Commented Nov 4, 2016 at 11:22
  • If you mean the password I use to log into ubuntu, yes I tried that one. I was able to log on to mysql with leaving the password blank, tried to change the password for root and creating a new user but this didn't work. After that I got the access denied message everywhere.
    – Tijmenh
    Commented Nov 4, 2016 at 11:26
  • So you only locked yourself out of LAMP, right? If so, please clarify that in your post. Commented Nov 4, 2016 at 11:29
  • alright, that's right. Added it in the question.
    – Tijmenh
    Commented Nov 4, 2016 at 11:31
  • Thanks got clarifying. I do not know anything about LAMP, that is why clarifying what you were locked out of was important. Maybe a naive answer is to ensure that when you uninstall the package you uninstall everything, including the files and folders where configuration and login information is stored. Did you try the option purge when uninstalling (that is if you installed through apt-get). Commented Nov 4, 2016 at 11:36

1 Answer 1


I managed to fix it by killing all mysql processes running: ps aux | grep mysql lists the processes and then killing them with sudo kill -9 [PID]. that allowed me to start a mysqld_safe process with the --skip-grant-tables flag and this allowed me to get into mysql with mysql -u root. Following this further to reset the password for root: https://help.ubuntu.com/community/MysqlPasswordReset

Also the password column has been changed to authentication_string in the user table in mysql_server 5.7 (latest version as of now).

After doing this I got it all installed and I can access phpmyadmin now!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .