This question has already been answered:

I installed a DB on Debian, I try to connect to it with the command mysql

And to me in response:

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

By default, the root should either have a root password, or there should be no password at all. And neither one nor the other does not work.

What to do?

Reported as a duplicate by participants aleksandr barakin , user194374, Denis , Ivan Pshenitsyn , Streletz Aug 17 '16 at 20:57 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • And there was no old base, which picked up the new installation? - Dmitry Kozlov
  • @DmitryKozlov No, before that the database was not on the server at all. - JamesJGoodwin

3 answers 3

In general, they should have been asked during the installation, but if not, then:

sudo dpkg-reconfigure --force mysql-server-5.5

If I have not confused anything, this command should give a window in which it will offer to set a new password for root. (I recall that the MySQL root has no relation to the system root, and it has a separate password.)

    Instructions for changing the password:

    1. Stop mysql

    2. Create a text file containing 1 line with the request to change the password

    For MySQL 5.7.6 and higher:

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

    For MySQL 5.7.5 and below:

     SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass'); 
    1. Start server from command line

      shell> mysqld_safe --init-file = / MyFileWallProsword &

    2. Stop server

    3. Start the server in the usual way.

    http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

       mysql -u root -p 

      and enter your password from Root (mysql`a superuser, not debian)

      • I already tried it. By default, the root should either have a root password, or there should be no password at all. And neither one nor the other does not work. - JamesJGoodwin
      • @JamesJGoodwin by default, the new password is suggested to be set during installation. Why you did not offer - a mystery.) - andreymal