Header Shadow Image


change mysql password for root when lost or forgot

To change your mysql password for any user, use the following procedure, in case the password is lost or forgotten.  For this post, we'll be changing it for the root user.

 

# mysql -u root -p

Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.1.69 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> update user set password=PASSWORD("MyR@nd0mP@ss") where User='root';
Query OK, 3 rows affected (0.39 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> flush previlidges;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'previlidges' at line 1
mysql> flush privilidges;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'privilidges' at line 1
mysql> flush priviliges;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'priviliges' at line 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

This method is preferred because the alternative:

# mysqladmin -u root -p'oldpassword' password newpass

Requires you to type your password on the command line, which is less secure.

Cheers,
TK

One Response to “change mysql password for root when lost or forgot”

  1. […] Disable autosave in WordPress change mysql password for root when lost or forgot […]

Leave a Reply

You must be logged in to post a comment.


     
  Copyright © 2003 - 2013 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License