咨询热线:4006-75-4006
售前:9:00-23:30 备案:9:00-18:00 技术:7*24h
解决过程:
1、编辑
/etc/my.cnf
在[mysqld] 配置部分添加一行
skip-grant-tables
2、保存后重启mysql
[root@localhost etc]# service mysqld restart Shutting down MySQL. [ OK ] Starting MySQL. [ OK ]
3、登录数据库重新设置root密码
[root@localhost ~]# mysql -uroot -p mysql Enter password: (直接回车进入)
执行
show databases;
后会给出以下提示:
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec)
接下来执行下列语句:
注意:
password("mysql")
里面的mysql为新设置的密码。
mysql> update user set password=password("mysql") where user='root'; 会给出提示: Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0
在执行:
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
就更改密码成功了
4、删除/etc/my.cnf文件中添加的“skip-grant-tables”行,重启mysql;
用新设的密码就能正常登录了;