Ubuntu Server MySQL - Unable to access with root user

I am new to Ubuntu Server

and I made the command:

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

      

Everything is going well and I am back at the command line. When I type:

mysql -u root

      

I got an error Access denied for user 'root'@'localhost' (using password: NO)

. Any ideas what I did wrong? I have tried uninstalling all 3 packages and reinstalling them to no avail. Google didn't help :(

+3


source to share


7 replies


Open terminal and run sudo dpkg-reconfigure mysql-server

enter new password for mysql

mysql -uroot -p

, Enter a new password



Note. You may need to add the mysql version to the first command. For example: dpkg-reconfigure mysqlserver-4.3

+6


source


One way to do it:

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

      

Then you enter mysql, enter the following command:

use mysql;
update user set password='*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' where User='root';
flush privileges;

      



After that, stop mysql and the start will be the same as usual

/etc/init.d/mysql stop
/etc/init.d/mysql start
mysql -u root -p

      

Your password should be: mypass

+2


source


For newer MySQL versions (for MariaDB <10.2 use the query below as it doesn't support changing user but still uses auth_socket)

If you install 5.7 and don't provide a password to the user root

, this will use the plugin auth_socket

. This plugin doesn't care and doesn't need a password. It just checks if the user is connected using a UNIX socket and then compares the username.

Taken from Change User Password in MySQL 5.7 Using "plugin: auth_socket" and https://askubuntu.com/a/801950/395418

So, to change plugin

to mysql_native_password

:

  • Login with sudo:

    sudo mysql -u root
    
          

  • Change plugin

    and set the password with one command:

    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test';
    
          

You can of course also use the above command to set a blank password.

For write-only, there is another way to change just plugin

without providing a password (leaving it blank):

    update mysql.user set plugin = 'mysql_native_password' where User='root';
    FLUSH PRIVILEGES;

      

+2


source


Before you reset try the password:

mysql -u root -p

      

After that, you need to write your password (don't worry if you don't see any * this is normal) and hit the back button.

+1


source


Tested on mysql 5.7.12

/etc/init.d/mysql stop
/usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
/usr/local/mysql/bin/mysql

      

Then from the open sql console enter the following commands:

UPDATE mysql.user 
    SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
    WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
exit;

      

Stop the current process and start it again. Then check the new password (should be MyNewPass ).

/etc/init.d/mysql stop
/etc/init.d/mysql start
/usr/local/mysql/bin/mysql -u root -p

      

+1


source


You need to install MySQL

$ mysqladmin -u root password NEWPASSWORD

      

0


source


To set a forgotten password, you need to stop mysql unmounting, start it with an option --skip-grant-tables

, then change the current password with mysqladmin -u root password NEWPASSWORD

.

You can find the complete password reset procedure here .

0


source







All Articles