ERROR 1044 (42000): Access denied for user ‘‘@‘localhost‘ to database ‘mysql‘忘记mysql密码

        今天去连公司的mysql数据库,忽然发现用原来的密码登录不进去,不知道是什么鬼,只能强制修改了!

我的操作系统是Centos6.5 ,

一共有两种方法:

1、修改配置文件

 [root@localhost~]#  service  mysqld  stop                --停掉mysql服务

 [root@localhost~]#  vi  /etc/my.cnf                            --编辑文件,在[mysqld]下添加一行    skip-grant-tables

 [root@localhost~]# service  mysqld  start               --开启mysql服务

 [root@localhost~]# mysql                                       --直接用mysql进入数据库,不需要验证用户名密码

mysql>   use  mysql ;                                                 --切换到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('NEW') where user='root';           --更新mysql的root密码为NEW

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       

[root@localhost~]#  service  mysqld   restart                    --重启mysql服务

Shutting down MySQL..                                      [  OK  ]
Starting MySQL.                                                  [  OK  ]
 

[root@rooo ~]#   mysql  -u root -pNEW

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.17 Source distribution

Copyright (c) 2000, 2014, 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


出现如上提示,则修改成功

2、mysqld_safe  -skip-grant-tables  &                --跳过密码验证

[root@localhost~]# mysql                                       --直接用mysql进入数据库,不需要验证用户名密码

mysql>   use  mysql ;                                                 --切换到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('NEW') where user='root';           --更新mysql的root密码为NEW

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       

[root@localhost~]#  service  mysqld   restart                    --重启mysql服务

Shutting down MySQL..                                      [  OK  ]
Starting MySQL.                                            [  OK  ]

 

[root@rooo ~]#   mysql  -u root -pNEW

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.17 Source distribution

Copyright (c) 2000, 2014, 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

出现如上提示,则修改成功

给新创建的用户授权

GRANT ALL PRIVILEGES ON *.* TO "zhang"@"%" IDENTIFIED BY "12345" WITH GRANT OPTION;


 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值