1、停止mysql服务 service mysqld stop
[root@wuwu1 ~]# service mysqld stopStopping mysqld: [ OK ]
2、 [root@wuwu1 ~]# mysqld_safe --skip-grant-tables
170403 08:02:17 mysqld_safe Logging to '/var/log/mysqld.log'.
170403 08:02:17 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
3、新开窗口 进入mysql
4、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("12345") where user="root";
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
ByeReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> update user set password=password("12345") where user="root";Query OK, 3 rows affected (0.00 sec)Rows matched: 3 Changed: 3 Warnings: 0mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> exitBye
flush privileges;刷新权限
5终止第一个窗口的后台进程
ctrl + z
6测试密码进入
mysql -uroot -p12345Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>