MYSQL忘记密码
1、 去到bin目录,右键进行命令行:
(1)net stop mysql57 (注:mysql名称去“服务”属性里查看)
(2)mysqld --skip-grant-tables
2、打开第二个cmd2窗口,连接mysql:
(1)mysql -u root -p
(2)Enter password: (注:这个直接回车)
(3)show databases;
(4)use mysql;
3、使用命令更改root密码:
(1)update mysql.user set authentication_string=password('输入新密码') where user='root';
(2)FLUSH PRIVILEGES;(刷新权限)
(3)net start mysql
或者grep 'temporary password' /var/log/mysqld.log
网上查了一下据说5.7 版本password 字段改成authentication_string password函数还是原来的password函数
mysql> update user set authentication_string=password('123') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1mysql忘记密码:
第一步:在命令行输入net stop mysql命令关闭mysql服务
第二步:使用--skip-grant-tables选项启动mysql服务(服务器将不加载权限判断,任何用户 都能访问数据库)
1、在命令行输入 mysqld --skip-grant-tables
2、命令运行之后,用户无法再输入指令,此时如果在任务管理器中可以看到名称为 mysqld的进程,则表示可以用root用户登录服务器了
第三步:打开另一个命令行窗口,输入不加密码的登录命令
1、mysql -u root
2、登录成功后可以使用update语句修改密码
3、修改完成后,必须使用flush privileges语句刷新权限表,这样新的密码才能生效
第四步:将输入mysqld --skip-grant-tables命令的命令行窗口关闭,接下来就可以使用新密码登录mysql服务器了
linux中的mysql5.7:
vim /etc/my.cnf:
[mysqld]skip-grant-tables
update user set authentication_string=password("输入新密码") where user="root";
然后重启systemctl restart mysqld
mysql -uroot
然后:
FLUSH PRIVILEGES;(刷新权限)
