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 totally new in linux/ubuntu I am trying to setup lamp on my OS, however I've installed apache , php , mysql by following commands:

sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
sudo apt-get install phpmyadmin

everything works fine except that i totally cannot log into MySQL(which leads to phpmyadmin failure login) getting the errors :

#1045 Cannot log in to the MySQL server
Access denied for user 'root'@'localhost' (using password: YES)

I googled the problem and also I have tried to reinstall all installed components, but the same result came up!

in windows i usually modified the content of mysql configure file but in ubuntu nothing is as same as windows!:)

can anybody help me on this, really need to setup lampp :-S

thanks in advanced

share|improve this question
up vote 10 down vote accepted

I think that you should reset the password of root user.

How to reset MySQL root password.

To reset your mysql password of root user, just follow these instructions.

Step1. Stop the mysql demon process using this command :

sudo service mysql stop

Step2. Start the mysqld demon process using the --skip-grant-tables option with this command:

sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &

Step3. Start the mysql client process using this command:

mysql -u root

Step4. From the mysql prompt execute this command to be able to change any password:


Step5. Then reset/update your password and quit:

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

Step6. Start the mysql demon process using this command :

sudo service mysql start

Now, you can log in to MySQL as root user.

share|improve this answer
thanks, that worked well and also found something else that in my re-installation i typed sudo apt-get remove mysql-server which removed mysql-server but keeps the config files so in my next installation it loads the last one's config files so the result would be the same! i just should type apt-get --purge mysql-server instead :) – dariush Jun 27 '12 at 21:45

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.