MySQL修改密码

MySQL修改密码

编码文章call10242025-06-10 12:13:054A+A-

拥有原来的用户名账户的密码


mysqladmin -u root -p password "test123"
Enter password: 【输入原来的密码】


忘记原来root密码


第一步:如果MySQL服务没有关闭,则关闭


service mysqld stop


第二步:在MySQL配置文件中增加忽略密码的配置,即在my.cnf中的[mysqld]下配置skip-grant-tables


vim /etc/my.cnf


如图,将:


第三步:开启MySQL服务


service mysqld start


第四步:进入MySQL数据库,不用输入密码,直接回车就行


mysql -u root -p


第五步:设置root用户密码


注意:代码中root_password就是新设置的密码

use mysql;
update mysql.user set authentication_string=password('root_password') where user='root';  


第六步:退出MySQL,关闭MySQL服务,将my.cnf中的skip-grant-tables注释


关闭MySQL服务


service mysqld stop


注释skip-grant-tables,如图


启动MySQL服务


service mysqld start


第七步:重新进入MySQL,输入新配置的密码

点击这里复制本文地址 以上内容由文彬编程网整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
qrcode

文彬编程网 © All Rights Reserved.  蜀ICP备2024111239号-4