When we use MySQL may forget root password for a variety of reasons, if that is the case, the database may be discarded, but today to share the way to retrieve the root password, or if you do not know the root password to change the root password, However, it is recommended that you carefully keep the root password to prevent some unnecessary trouble to retrieve the administrator password:
[[Email protected]~]# service mysqld Stop
Shutting down MySQL .... Determine
[[Email protected]~]# vim/etc/init.d/mysqld
Approximately 283 lines:
$bindir/mysqld_safe--datadir= "$datadir"--pid-file= "$mysqld _pid_file_path" $other _args >/dev/null2>&1 &
Wait_for_pid created "$!" " $mysqld _pid_file_path "; Return_value=$?
Change to
$bindir/mysqld_safe --skip-grant-tables--skip-networking
--datadir= "$datadir"--pid-file= "$mysqld _pid_file_path" $other _args >/dev/null2>&1 &
Wait_for_pid created "$!" " $mysqld _pid_file_path "; Return_value=$?
Save exit
mysql> use MySQL
Readingtable information for completion of table and column names
You canturn off this feature to get a quicker startup with-a
Databasechanged
Mysql> select User,host,password from user;
+---------+-----------------------+-------------------------------------------+
|user | Host | password |
+---------+-----------------------+-------------------------------------------+
|root | localhost |*4941369bd46398a2bdeec85411065d7137d4ea0f |
|root | Localhost.localdomain |*4941369bd46398a2bdeec85411065d7137d4ea0f |
|root | 127.0.0.1 |*4941369bd46398a2bdeec85411065d7137d4ea0f |
|tianke | % |*a399693a49f7ec7c548d0fc376fa52ad293a552f |
|tianke1 | % |*eeac51414f1ae247d67f47a875bdb134cf39986c |
+---------+-----------------------+-------------------------------------------+
5 Rowsin Set (0.01 sec)
Change root password
mysql> Update user Setpassword=password (' 123456 ') whereuser= ' root ';
Queryok, 3 Rows Affected (0.00 sec)
Rowsmatched:3 Changed:3 warnings:0
Then stop the service again and then change the count back to restart MySQL.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MySQL Recover admin password