How to reset the root password for MySQL

RESETTING THE ROOT PASSWORD FOR MYSQL

To reset the root password for MySQL, follow these steps:

  1. Log in to your account using SSH.
  2. Stop the MySQL server using the appropriate command for your Linux distribution:For CentOS and Fedora, type:
// For CentOS and Fedora, type:
# service mysqld stop
// For Debian and Ubuntu, type:
# service mysql stop

3. Restart the MySQL server with the —skip-grant-tables option. To do this, type the following command:

# mysqld_safe --skip-grant-tables &

4. Log into MySQL using the following command:

# mysql

5. At the mysql> prompt, reset the password. To do this, type the following command, replacing NEW-PASSWORD with the new root password:

UPDATE mysql.user SET Password=PASSWORD('NEW-PASSWORD') WHERE User='root';

6.At the mysql> prompt, type the following commands:

FLUSH PRIVILEGES;
exit;

7. Stop the MySQL server using the following command. You will be prompted to enter the new MySQL root password before the MySQL server shuts down:

# mysqladmin -u root -p shutdown

8. Start the MySQL server normally. To do this, type the appropriate command for your Linux distribution:

// For CentOS and Fedora, type:
# service mysqld start
// For Debian and Ubuntu, type:

# service mysql start

You may also like...

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *