When we use MySQL, it is possible to forget rootpassword for a variety of reasons, assuming that the database might be discarded. But today to everyone to share the way to find Rootpassword or in the case do not know Rootpassword change Rootpassword, but still suggest to Rootpassword carefully custody, Prevent some unnecessary trouble getting back to admin 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 Rootpassword
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 restarting MySQL.
MySQL Recover admin password