一、Linux下mysql密码恢复
1
2
3
4
5
6
|
service mysqld stop
mysqld_safe --skip-grant-tables;ctrl+z暂停
mysql -u root -p
mysql> use mysql;
mysql> update user set password=password( '新密码' ) where user= 'root' ;
mysql> flush privileges;
|
重新登录shell使用新密码!
二、Windows下mysql密码恢复
1. net stop mysql
2. 切换到mysql安装目录\bin下面
3. mysqld-nt --skip-grand-tables
4.再新打开一个cmd窗口输入:mysql -u root -p #无密码登陆
5. update user set password=password('新密码') where user='root';
三、开启mysql远程登录
mysql> grant all privileges on *.* to 'root'@'%' identified by '远程密码';
mysql> flush privileges;
参数说明:
all:授权所有操作命令(增、删、改、查)
*.* :授权所有数据库和所有表
% :允许所有IP来访问mysql
flush privileges; :刷新授权表
查看是否开启,显示有如下一条,说明已经允许所有远程登陆
mysql> use mysql;
mysql> select host, user, password from user;
| % | root | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 |
四、其他命令
revoke all privileges on *.* from 'root'@'%'; #撤销已赋予用户的权限;
show grants; :查看当前用户权限
show grants for 用户@localhost; : 查看其他用户权限
本文转自 李振良OK 51CTO博客,原文链接:http://blog.51cto.com/lizhenliang/1294746,如需转载请自行联系原作者