Error 1045 (28000) Access Denied for user ‘root’@’localhost’

Error 1045 (28000) Access Denied for user ‘root’@’localhost’

Trying to log into MySQL server via command line using mysql -u root and getting error 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: yes) on the terminal, it means that MySQL root user password is incorrect or the root user has no privileges.

The Error 1045 MySQL (28000): Access Denied for User ‘root’@’localhost’ (using Password: yes) can be fixed in two ways, first set a new password for the MySQL root user or reset the root user’s privileges appropriately.

Steps to fix error 1045 MySQL (28000): Access denied for user ‘root’@’localhost’ (using password: yes) ubuntu:

Step 1: Stop MySQL Server

To shut down the MySQL server, for this you can use the systemctl command:

sudo systemctl stop mysql.service

Step 2: Skip Grant Tables and Networking

To access MySQL server without valid password, you need to skip grant tables and networking validation, for this you can use this command:

sudo systemctl set-environment MYSQLD_OPTS="--skip-networking --skip-grant-tables"

The MySQL environment has been configured to use it without a password. Now, can log in to MySQL server without password.

Step 3: Start MySQL Server

Now the MySQL server has to be started so that the password can be reset, for this you can use the command:

sudo systemctl start mysql.service

Step 4: Log in as a MySQL Root User

To access MySQL Server and its service as a root user without a password, Type this command on the terminal and you can log in to MySQL Server:

sudo mysql -u root

Step 5: Set New Password For Root User

To select a MySQL database and flush privileges on the terminal window, you use the “use mysql” and “flush privileges;” command:

flush privileges; use mysql;

To set a new password for the MySQL root user, Type alter command on a ubuntu terminal window:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '(YOUR_NEW_PASSWORD)';

Here, your_new_password in command, change it to your new password. And then exit the mysql shell by using this exit command:

Exit;

And this will fix the error “1045 (28000): access denied for user ‘root’@’localhost’ (using password: yes)” on ubuntu.

Step 6: Stop all MySQL processes and restart the MySQL server

Once the root password is set, the changes made can be applied. For this, stop or stop all the MySQL server processes and restart the server, you can do this by:

To stop mysql proccesses:

sudo killall -u mysql

To restart mysql server:

sudo systemctl restart mysql.service

Step 7: Log in to MySQL With New Password

With the steps you’ve followed so far, the new password for your MySQL root user has been set. Now, you can login into MySQL server as root user with the new password, you can use:

sudo mysql -u root -p

Conclusion

That’s it; A step-by-step guide on how to fix error “1045 (28000): access denied for user ‘root’@’localhost’ (using password: yes)” by changing MySQL root user password ubuntu.

Recommended Tutorials

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *