Step 1 .
Stop MySQL database using the following command
# service mysqld stop
Stopping mysqld: [ OK ]
Step 2:
Restart mysqld with --skip-grant-tables and --skip-networking option. This enables anyone to connect to mysql without a password and with all privileges. Because this is insecure --skip-networking should be used in conjunction to prevent remote clients from connecting.
This is shown below:
# mysqld_safe --skip-grant-tables --skip-networking &
[1] 8291
130708 19:28:13 mysqld_safe Logging to '/var/log/mysqld.log'.
130708 19:28:13 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Step 3:
Connect to MySQL and reset the root password as shown below.
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.52 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> UPDATE mysql.user SET Password=PASSWORD('newrootpassowrd') WHERE User='root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
Step 4:
Restart mysql service
$service mysqld restart
转载于:https://blog.51cto.com/hsuing/1687932
本文介绍了一种在忘记MySQL root密码的情况下重置的方法。通过停止MySQL服务、使用特定选项重启服务、连接到MySQL并更新root用户的密码,最后重启MySQL服务完成整个重置过程。
1294

被折叠的 条评论
为什么被折叠?



