首页 > 编程知识 正文

如何重置mysql数据库密码,mysql如何重置密码

时间:2023-05-04 14:36:12 阅读:187584 作者:4750

忘记了Mysql的root用户密码,尝试连接时提示:

mysqladmin: connect to server at 'localhost' failed

ERROR : Access denied for user 'root'@'localhost' (using password: NO).

没办法,只好重设Mysql的密码了。下面操作须在root用户下进行。

 停止mysql服务

# service mysqld stop

 

 启动mysqld_safe ,跳过启动授权表。启动时加上skip-grant-tables参数目的是在启动mysql时不启动grant-tables,授权表。这样就可以修改root的密码了。

# mysqld_safe --skip-grant-tables &

 登录mysql,并修改密码:

# mysql -uroot -p      ----要求输入密码时,直接回车即可。

> use mysql;

> update user set password=PASSWORD('12345678') where user="root";    ---将root密码设置为12345678

>  flush privileges;

> quit

 杀死mysqld_safe进程,并重启mysqld。

# kill -9  11283  (11283为mysqld_safe进程)

# service mysqld start

# mysql -uroot -p     (输入密码12345678即可)

ERROR 1290 (HY000): The MySQL server is running with the--skip-grant-tables option so it cannot execute thisstatement 这个错误执行flush privileges后再次授权就可以了。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。