mysql 密码丢失_MySQL的root密码忘记或丢失的解决方法一例

-bash-4.2$ service mysql status

SUCCESS! MySQL running (2670)

-bash-4.2$ mysql -u root -p

Enter password:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

以下是密码忘记的解决方法:

修改MySQL的参数设置:

# vi /etc/my.cnf

在[mysqld]的段最后一行加上一句:skip-grant-tables

例如:

[mysqld]

........................

log-bin=mysql-bin

innodb_data_file_path = ibdata1:12M;ibdata2:100M;ibdata3:300M:autoextend

innodb_file_per_table=on

max_connections=500

skip-grant-tables    --新增加行

保存并且退出vi.

重启MySQL服务:

[root@chenfeng subsys]# service mysql restart

Shutting down MySQL. SUCCESS!

Starting MySQL. SUCCESS!

-bash-4.2$ mysql    --不用输密码直接登录

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.15-log Source distribution

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| chenfeng           |

| mysql              |

| performance_schema |

| test               |

+--------------------+

5 rows in set (0.00 sec)

MySQL [(none)]> 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 [mysql]>  UPDATE user SET Password = password ('12345678') WHERE User ='root';   --修改为新密码12345678

Query OK, 4 rows affected (0.00 sec)

Rows matched: 4  Changed: 4  Warnings: 0

MySQL [mysql]>

MySQL [mysql]> flush privileges;   --刷新一下权限表

Query OK, 0 rows affected (0.00 sec)

MySQL [mysql]> quit

Bye

将MySQL的参数设置修改回来:

# vi /etc/my.cnf

将刚才在[mysqld]的段中最后一行加上的skip-grant-tables删除,然后保存退出。

重启MySQL服务:

[root@chenfeng subsys]# service mysql restart

Shutting down MySQL. SUCCESS!

Starting MySQL. SUCCESS!

重新用新密码登录:

-bash-4.2$ mysql -u root -p12345678      --12345678为新密码

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MySQL connection id is 7

Server version: 5.6.15-log Source distribution

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> 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 [mysql]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| chenfeng           |

| mysql              |

| performance_schema |

| test               |

+--------------------+

5 rows in set (0.00 sec)

MySQL [mysql]>

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值