Reset the root password for MySQL

Expand / Collapse

Summary

This article explains how to reset the root password for MySQL. Choose the appropriate section based on your Operating System. It is NOT recommended to perform these steps with a control panel such as Plesk, cPanel, or Ensim.

Steps

Linux

Log into the server via SSH.  Once logged in as the root user, perform the follow commands at the prompt:
# service mysqld stop
# /usr/bin/mysqld_safe --skip-grant-tables --skip-networking &
# mysql -u root
mysql> use mysql;
mysql> UPDATE user SET Password=PASSWORD('your password here') WHERE User='root';  
mysql> exit
# service mysqld stop
# service mysqld start

Windows

Log into the server via RDC.  Once logged in as the administrative user, perform the follow commands at the prompt:
  1. Locate my.ini (usually in C:\Program Files\MySQL\MySQL Server X.Y, where X- is a major and Y is a minor version of MySQL).
  2. Add the following lines under [mysqld] section:
  3. skip-grant-tables
    skip-networking 

  4. Restart the mysqld service.
  5. In the Windows command shell execute: mysql -u root  This will log you into MySQL without a password as you're performing the skip-grant-tables command above.
  6. In the mysql client command window execute the following commands:
  7. mysql> use mysql;
    mysql> UPDATE user SET Password=PASSWORD('your password here') WHERE User='root';
    mysql> exit
  8. Remove (or comment-out with the # ) the added lines as it is a security risk to leave these in the my.ini file:
  9. # skip-grant-tables
    # skip-networking 
  10. Restart the mysqld service and log in with the new password.


Rate this Article:


Details
Category: MySQL

Last Modified:Wednesday, November 13, 2013 7:15 AM

Type: HOWTO

Level: Intermediate

Article not rated yet.

Article has been viewed 1,857 times.

Options
Email Article Email Article


Social Bookmarks Social Bookmarks