I just installed a fresh ubuntu 16.04, I installed mysql on it, but when I tried to enter it

$ mysql -uroot 

an error is issued

ERROR 1698 (28000): Access denied for user 'root' @ 'localhost'

Although, I still can go there through

 $ sudo mysql -uroot 

Tell me how to do that from under a regular user to go there?


added from comment:

Put through

 $ sudo apt-get install mysql-server $ sudo apt-get install mysql-client 

I was asked to set a password for the mysql root user, I left it empty, and if I try to log in with the -p flag, the system asks for a password, I press enter, and I get the same error.

  • one
    1. How exactly did you “install” the mysql server and the mysql client? 2. during this “statement” you were asked to create a password for the root user in the mysql server? 3. if so, does this password come up in response to a password prompt when running mysql -u root -p ? 4. In the home directory of the user under whose name you work, there is a file .my.cnf ? 5. .my.cnf there a .my.cnf file in the root user home directory? - aleksandr barakin
  • I sudo apt-get install mysql-server through sudo apt-get install mysql-server and sudo apt-get install mysql-client , but it was suggested, I left empty, if I try to enter with the -p flag, the system asks for a password, I press enter, and I get the same error. The .my.cnf file is not in ~ or in /root - Ghost16
  • means to you here: stackoverflow.com/a/427773/178576 - aleksandr barakin
  • That is, it turns out that you can not allow a root without a password to enter the database? - Ghost16
  • Alas, did not catch the meaning of the last question. If you do not want to enter a password, create a file ~/.my.cnf with the appropriate content . - aleksandr barakin

3 answers 3

how to reset the password for the root user mysql in the debian- based distribution, for example, described in this answer: How do I find out the root password for the MySQL database in Ubuntu?

To avoid entering a password every time you call the mysql client, you can use a custom configuration file: How do I specify default values ​​when starting the mysql client?

  • reset password mysql> update user set authentication_string=PASSWORD("123") where User='root'; (the server was pre-loaded via sudo /etc/init.d/mysql restart ) anyway, the same mysql -uroot -p123 error mysql -uroot -p123 > mysql: [Warning] can be insecure. > ERROR 1698 (28000): Access denied for user 'root' @ 'localhost' - Ghost16
  • @ Ghost16, I also specified a link to the correct distribution method of changing the root user password in mysql. - aleksandr barakin

You can create a new user with full rights.

 $ sudo mysql -uroot CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost'; FLUSH PRIVILEGES; EXIT; $ mysql -unewuser -ppassword 

To work with the database, use the new user newuser instead of root.

    In mariadb debian9.5:

    `` sql

     sudo mysql -u root use mysql; update user set plugin='' where User='root';-- Want be the Empty string!!! flush privileges; exit; 

    `` `

    • Please correct your message. Explain what this snippet does. - 0xdb