#1045 Cannot log in to the MySQL server
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:
FLUSH PRIVILEGES;
Step5. Then reset/update your password and quit:
SET PASSWORD FOR root@'localhost' = PASSWORD('password');
quit
Step6. Start the mysql demon process using this command :
sudo service mysql start
Now, you can log in to MySQL as root user.
Related videos on Youtube
dariush
Updated on September 18, 2022Comments
-
dariush over 1 year
I am trying to setup LAMP on my OS, so I have installed
apache
,php
,mysql
using the 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 cannot log into MySQL (which leads to
phpmyadmin
failure login). I'm 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 I have also tried to reinstall all installed components, but the same result came up!
On Windows, I usually modified the content of
mysql
configuration file, but in Ubuntu nothing is the same as Windows! -
dariush almost 12 yearsthanks, 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 typeapt-get --purge mysql-server
instead :) -
Fortran about 7 yearsAfter Step3 i get error "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) [1]+ Exit 1 sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking " on Ubuntu 16.04