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

I tried all the fixes that I found and I cannot change my MySQL root password. In the shell, if I type mysql -u root , I get

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

When I switch to PHP MyAdmin, I get the following:

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

It 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.

Thanks.

+5
source share
5 answers

MYSQL OVERVIEW

To get started, read the mysql manual: https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html.

The steps will show you how to turn off the service and start it with an overridden command that does not require passwords, then you will reset the password. From the manual:

Stop the MySQL server, then restart it with the --skip-grant-tables option. This allows any user to connect without a password and with all privileges and disables account management operators such as ALTER USER and SET PASSWORD . Since this is unsafe, you can use --skip-grant-tables in combination with --skip-networking to prevent remote clients from connecting.

Connect to the MySQL server using the mysql client; no password is required because the server was started with --skip-grant-tables :

shell> mysql

In the mysql client, tell the server to reload the grant tables so that the account management statements work:

mysql> FLUSH PRIVILEGES;

Then change the password of the account 'root'@'localhost' . Replace the password with the password you want to use. To change the password for the root account with a different part of the host name, change the instructions to use this host name.

MySQL 5.7.6 and later:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

MySQL 5.7.5 and earlier:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

Or directly on the user table:

UPDATE mysql.user SET password=PASSWORD('mynewpassword') WHERE user='root';

XAMPP SPECIAL

Stop the MySQL service. Open a command window. Go to the MySQL XAMPP directory:

> cd \xampp\mysql\bin\

Start the service without protection (note that you are using mysqld, not mysql):

> mysqld.exe --skip-grant-tables

The MySQL service will work in this window, so open another command window and switch to the MySQL XAMPP directory:

> cd \xampp\mysql\bin\

Launch the MySQL client:

> mysql

Update Password:

mysql> UPDATE mysql.user SET password=PASSWORD('mynewpassword') WHERE user='root';

Exiting MySQL:

mysql> \q

Use the task manager to undo mysqld.exe, which still works. Restart the MySQL service.

+7
source

My problem has been resolved below.

When I enter the command below, 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 issue, follow these steps: Enter the command

 sudo mysqld_safe --skip-grant-tables & 

Then the error below 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, follow the lines below.

  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 the MySQL prompt will appear. then after setting the password.

  2. PRIVILEGES OF RINSING;

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

  2. After that I look below. mysql -u root -p

+3
source
 First Run CMD mode E:\xampp\mysql\bin>mysql.exe -u root -p Screenshot: 

enter image description here

+2
source

If you are using Ubuntu, go to:

 /etc/phpmyadmin/config-db.php 

If you do not have permission to view this archive, open your terminal (ctrl + alt + t). and type: sudo chmod 777 /etc/phpmyadmin/config-db.php

Now you can see this document with the user ID and password. remember to protect this document again

sudo chmod 000 /etc/phpmyadmin/config-db.php

0
source

For Windows users: before starting password recovery, try the command line:

 mysql -uroot -pyourpassword 

as is, without a space, as shown below:

Printout of my MySQL login

I don’t have time to explain why, but if you want to know more, check how the "MySQL XX Command Line Client" shortcut works on your computer.

Over time, verify that the mysql paths are in the PATH variable.

My computer uses these paths shown below. Your computer may use other ways. C: \ ProgramData \ MySQL \ MySQL Server 8.0 C: \ Program Files \ MySQL \ MySQL Server 8.0 \ bin

0
source

Source: https://habr.com/ru/post/1263226/


All Articles