Database and Indexing » MySQL

ID #1010

How do I reset (root) password for MySQL?

Alternative question: I forgot MySQL root password. How do I reset it?

MySQL database daemon (mysqld-nt.exe on Windows, mysqld on Linux and *nix) by default allows connection only after validating it against the users in the 'user' table in the 'mysql' database - what is referred to as the grant table.

You can turn this off by starting the server using --skip-grant-table option.

So, the steps would be:

  1. Stop MySQL server / daemon, if running.
     
  2. Start the daemon as
    mysqld --skip-grant-table (On *nix / Linux et al)
    mysqld-nt.exe --skip-grant-table (On Windows)
     
  3. Connect using the client and change the password
    $mysql -u root (Don't specify any password, it won't be verified anyway)
    mysql> use mysql;
    mysql> UPDATE user SET Password='Password' WHERE User='root';

     
  4. Update privileges
    mysql> FLUSH PRIVILEGES;

 

There's another way out... a slightly more cumbersome. That uses the MySQL feature that when it starts, it can execute a set of SQL statements.

That's in another FAQ :)

 


Last update: 2009-01-25 04:52
Author: Edujini Labs Pvt Ltd
Revision: 1.1

Print this record Print this record
Send to a friend Send to a friend
Show this as PDF file Show this as PDF file
Export as XML-File Export as XML-File

Please rate this entry:

Average rating: 0 from 5 (0 Votes )

completely useless 1 2 3 4 5 most valuable

You cannot comment on this entry