mysql的root密码忘了(忘记MySQL的root密码的解决方法)

江城决的小站(1)修改配置文件my.cnf,在配置文件[MySQLd]下添加skip-grant-tables,重启MySQL服务即可免密码登录,今天小编就来说说关于mysql的root密码忘了?下面更多详细答案一起来看看吧!

mysql的root密码忘了(忘记MySQL的root密码的解决方法)

mysql的root密码忘了

江城决的小站

(1)修改配置文件my.cnf,在配置文件[MySQLd]下添加skip-grant-tables,重启MySQL服务即可免密码登录

其中--skip-grant-tables 选项前面曾经介绍过,意思是启动 MySQL 服务的时候跳过权限表认证。 启动后,连接到 MySQL 的 root 将不需要口令。

# SERVER SECTION

# ----------------------------------------------------------------------

#

# The following options will be read by the MySQL Server. Make sure that

# you have installed the server correctly (see above) so it reads this

# file.

#

[mysqld]

skip-grant-tables

(2)用空密码的 root 用户连接到 MySQL,并且更改 root 口令:

[root@localhost mysql]# mysql -uroot

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 53

Server version: 5.0.41-community-log MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql>

mysql> update user set password=password('123') where user='root' and host='localhost';

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

mysql> use mysql;

mysql> update user set authentication_string = NULL where user = 'root';

Query OK, 1 row affected (0.00 sec)

上面是先用grant的方式修改root密码,但是由于使用了配置了skip-grant-tables 选项,使用“alter user”命令更改密码失败,直接更新 user 表的 authentication_string字段后更改密码成功。

(3)到my.cnf 中删除skip-grant-tables选项,然后直接用mysql -uroot免密码登录后,在执行如下语句重设密码

mysql> update user set password=password('123') where user='root' and host='localhost';

(4)重新用 root 登录时,必须输入新口令。

mysql如何修改root用户的密码

方法1: 用SET PASSWORD命令

首先登录MySQL。

格式:mysql> set password for 用户名@localhost = password('新密码');

例子:mysql> set password for root@localhost = password('123');

方法2:用mysqladmin

格式:mysqladmin -u用户名 -p旧密码 password 新密码

例子:mysqladmin -uroot -p123456 password 123

方法3:用UPDATE直接编辑user表

首先登录MySQL。

mysql> use mysql;

mysql> update user set password=password('123') where user='root' and host='localhost';

mysql> flush privileges;

方法4:在忘记root密码的时候,可以这样

以windows为例:

1. 关闭正在运行的MySQL服务。

2. 打开DOS窗口,转到mysql\bin目录。

3. 输入mysqld --skip-grant-tables 回车。--skip-grant-tables 的意思是启动MySQL服务的时候跳过权限表认证。

4. 再开一个DOS窗口(因为刚才那个DOS窗口已经不能动了),转到mysql\bin目录。

5. 输入mysql回车,如果成功,将出现MySQL提示符 >。

6. 连接权限数据库: use mysql; 。

6. 改密码:update user set password=password("123") where user="root";(别忘了最后加分号) 。

7. 刷新权限(必须步骤):flush privileges; 。

8. 退出 quit。

9. 注销系统,再进入,使用用户名root和刚才设置的新密码123登录。

,

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页