Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL error: #1045 - Access denied for user 'root'@'localhost' (using password: YES)

Tags:

mysql

I have tried every fix that I have found, and I cannot change my root MySQL password. At the shell, if I type in mysql -u root, I get

Access denied for user 'root'@'localhost' (using password: NO)

When I go to PHP MyAdmin, I get this:

#1045 - Access denied for user 'root'@'localhost' (using password: YES)

This all started when I was forced to enter a new password for MySQL. I have NO idea how to fix this and I am desperate.

Thank you.

like image 761
SandyS Avatar asked Jan 24 '17 02:01

SandyS


People also ask

How do I find MySQL errors?

On Ubuntu systems, the default location for the MySQL is /var/log/mysql/error. log . In many cases, the error logs are most easily read with the less program, a command line utility that allows you to view files but not edit them: sudo less /var/log/mysql/error.

Why MySQL is not working?

normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.

What is 42000 error in MySQL?

The ERROR 1064 (42000) mainly occurs when the syntax isn't set correctly i.e. error in applying the backtick symbol or while creating a database without them can also create an error, if you will use hyphen in the name, for example, Demo-Table will result in ERROR 1064 (42000).


1 Answers

my problem was solved in below way.

When I was entered below command then I will get an error. sudo mysql -u root -p

Enter password:   
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES).

To resolve this follow below steps. Enter command,

sudo mysqld_safe --skip-grant-tables &

Then the below error occurred.

2018-12-17T06:43:33.106111Z mysqld_safe Logging to syslog.
2018-12-17T06:43:33.108971Z mysqld_safe Logging to '/var/log/mysql/error.log'.
/usr/bin/mysqld_safe: 152: /usr/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Permission denied
2018-12-17T06:43:33.111388Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
/usr/bin/mysqld_safe: 152: /usr/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Permission denied

To resolve this error, then follow below lines.

  1. systemctl stop mysql
2018-12-17T06:48:42.971692Z mysqld_safe Logging to syslog.
2018-12-17T06:48:42.974451Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2018-12-17T06:48:42.976653Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
  1. sudo mkdir -p /var/run/mysqld

  2. sudo chown mysql:mysql /var/run/mysqld

  3. sudo mysqld_safe --skip-grant-tables &

2018-12-17T06:50:39.135292Z mysqld_safe Logging to syslog.
2018-12-17T06:50:39.137938Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2018-12-17T06:50:39.152966Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
  1. Then connect mysql -u root. then MySQL prompt will appear. then after set your password.

  2. FLUSH PRIVILEGES;

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
  1. systemctl stop mysql

  2. After that loing in below way. mysql -u root -p

like image 131
netajik Avatar answered Oct 02 '22 10:10

netajik