ITPub博客

首页 > 数据库 > MySQL > MySQL忘记root密码,解决办法

MySQL忘记root密码,解决办法

原创 MySQL 作者:fengsongtao123 时间:2016-10-01 14:46:49 0 删除 编辑
1、启动MySQL
[root@localhost ~]# mysqld_safe --skip-grant-tables &    

2、登录MySQL
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.25a-log Source distribution

Copyright (c) 2000, 2011, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| allen              |
| mysql              |
| mytest             |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.00 sec)

mysql> use mysql
Database changed
mysql> update user set password=PASSWORD("123456") where user="root";     --修改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> quit
Bye

3、重新使用密码登录
[root@localhost ~]# mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.25a-log Source distribution

Copyright (c) 2000, 2011, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| allen              |
| mysql              |
| mytest             |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.00 sec)


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30373263/viewspace-2125823/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-07-25

  • 博文量
    96
  • 访问量
    259435