Home  >  Q&A  >  body text

Root user is denied access to MySQL

I recently installed MySQL on x86_64 *Ver 8.0.28-0ubuntu0.20.04.3 for Linux ((Ubuntu))*

After installation, when I try to access my shell it says

Error 1045 (28000): Access denied for user "root"@"localhost" (using Password: No)

With or without sudo, I know this has answers on stack and other forums but none of them seem to have helped me, I've tried reinstalling the MySQL server but that didn't help either, I've tried skipping the grant option , and then changed the root password but it also failed. I need help, thank you

P粉208469050P粉208469050345 days ago724

reply all(1)I'll reply

  • P粉752812853

    P粉7528128532023-11-10 09:14:34

    You can reset your password with a single downtime. For version 8, just follow the steps below.

    1. Stop Mysql service $ systemctl stop mysql
    2. Now run the Mysql service in skip authorization table mode. $ mysqld_safe --skip-grant-tables &
    3. Log in to the service now $ mysql -uroot
    4. Execute refresh permission query
    5. Execute change query $ alter user 'root'@'localhost'identified by 'password';
    6. Stop the mysql service now $ systemctl stop mysql
    7. Now restart the mysql service $ systemctl restart mysql
    8. Now try to log in with the updated password

    reply
    0
  • Cancelreply