1

I can't get access to my MySQL databases. Problem:

root@server:~# mysql -uroot

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

Trying to reset password:

  • /etc/init.d/mysql stop
  • mysqld_safe --skip-grant-tables &

leads to:

root@server:~# ... mysqld_safe Logging to syslog. ... mysqld_safe Logging to '/var/log/mysql/error.log'. ... mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

as a result:

root@server:~# mysql -uroot

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

root@server:~# mysql -u root -p

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

Heinz
  • 61
  • 1
  • 7
  • 1
    Does this answer your question? [MySql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)](https://stackoverflow.com/questions/42742075/mysql-error-1045-28000-access-denied-for-user-rootlocalhost-using-passw) and many others. – Ken White Dec 04 '19 at 13:46
  • No, not at all. Where in this link do you see the solution? I've already read 20 Threads on Stack Overflow about it and did 5 Tutorials. – Heinz Dec 04 '19 at 13:54

2 Answers2

4

Here is the solution that worked for me.

sudo mysql --defaults-file=/etc/mysql/debian.cnf

Now I'm in ! :-)

DROP USER 'root'@'localhost';

CREATE USER 'root'@'localhost' IDENTIFIED BY 'the_password';

GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' WITH GRANT OPTION;

GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' WITH GRANT OPTION;

Thanks to Maoz Zadok in:

https://stackoverflow.com/a/49778695/12226925

Community
  • 1
  • 1
Heinz
  • 61
  • 1
  • 7
0

Directions from Section B.4.3.2.2 for Resetting Root Password on Unix and Unix-Like Systems.

  1. As root, kill the mysqld process.
  2. Create a text file containing the password-assignment statement on a single line: ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword';
  3. Start MySQL: mysqld --init-file=/path/to/file-from-step-2 --user=mysql
  4. Delete the file you created in step 2
scuba_mike
  • 360
  • 3
  • 12