Mysql是目前很主流的免费关系型数据库之一,修改mysql数据库密码可以说是很常见的操作。本文实际操作mysql5.7版本,分别实验了Windows、Linux两种环境下记得密码和不记得密码两种情况如何修改mysql的登录密码。
目录
注意:mysql5.7及以后版本,user用户表的密码字段由之前的password被改成了加密的authentication_string字段。
一、Windows
1、记得密码
主要有update、mysqladmin两种方式
(1)update方式
cmd命令窗,进入到mysql的bin目录,默认一般是在C:\Program Files\MySQL\MySQL Server 5.7\bin
>cd C:\Program Files\MySQL\MySQL Server 5.7\bin
连接mysql
>mysql -uroot -p
Enter password:
输入密码回车,连接到mysql终端!!!
更新root密码
mysql>use mysql;
mysql>select user,authentication_string,host from user;
mysql>update user set authentication_string = password('rootpassword') where user = 'root' and host = 'localhost';
这里host = 'localhost' 表示修改的是root本地localhost访问的密码,一个root账户可能指定了多个不同的host,根据实际修改,可以设置所有的root密码相同( and host = 'localhost'去掉即可)。
刷新权限后生效</