1、首先停止数据库
在[mysqld]的段中加上一句:skip-grant-tables
[mysqld]
skip-grant-tables
[root@wolf bin]# service mysqld stop
Shutting down MySQL.. [ OK ]
[root@wolf bin]# service mysqld start
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
5、在[mysqld]的段中删除或注释:skip-grant-tables
[mysqld]
#skip-grant-tables
[root@wolf bin]# service mysqld restart
Shutting down MySQL.. [ OK ]
Starting MySQL. [ OK ]
[root@wolf bin]# mysql -uroot -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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.
[root@wolf bin]# service mysqld stop
2、在my.cnf中加入skip-grant-tables
[root@wolf bin]# vi /etc/my.cnf在[mysqld]的段中加上一句:skip-grant-tables
[mysqld]
skip-grant-tables
[root@wolf bin]# service mysqld stop
Shutting down MySQL.. [ OK ]
[root@wolf bin]# service mysqld start
Starting MySQL. [ OK ]
3、进入mysql
[root@wolf bin]# mysqlWelcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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
4、update更新密码
mysql> UPDATE user SET Password = password ( '123' ) WHERE User='root';Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
5、在[mysqld]的段中删除或注释:skip-grant-tables
[mysqld]
#skip-grant-tables
[root@wolf bin]# service mysqld restart
Shutting down MySQL.. [ OK ]
Starting MySQL. [ OK ]
[root@wolf bin]# mysql -uroot -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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.