The MySQL root password allows the root user to have full access to the MySQL database. You must have (Linux) root administrator access to the server to reset MySQL root password.
Use the following steps to reset a MySQL root password by using the command line interface.

Stop The MySQL Service

(Ubuntu And Debian) Run the following command:

sudo /etc/init.d/mysql stop

(CentOS, Fedora, And Red Hat Enterprise Linux) Run the following command:

sudo /etc/init.d/mysqld stop

Start MySQL Without A Password

Run the following command. The ampersand (&) at the end of the command is required.

sudo mysqld_safe --skip-grant-tables &

Connect To MySQL

Run the following command:

mysql -uroot

Set A New MySQL Root Password

Run the following command:

use mysql;
update user set authentication_string=PASSWORD("mynewpassword") where user='root';
flush privileges;
quit

Stop And Start The MySQL Service

(Ubuntu And Debian) Run the following commands:

sudo /etc/init.d/mysql stop
...
sudo /etc/init.d/mysql start

(CentOS, Fedora, And Red Hat Enterprise Linux) Run the following commands:

sudo /etc/init.d/mysqld stop
...
sudo /etc/init.d/mysqld start

Log In To The Database

Test the new password by logging in to the database.

mysql -u root -p

You are prompted for your new password.

People reacted to this story.
Show comments Hide comments
Comments to: Reset MySQL root password via command line – mysql 5.7
Write a response

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

Attach images - Only PNG, JPG, JPEG and GIF are supported.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Login

Welcome to Typer

Brief and amiable onboarding is the first thing a new user sees in the theme.
Join Typer
Registration is closed.
%d bloggers like this: