编辑my.cnf允许空密码登录
[root@7Core ~]# vi /etc/my.cnf
#在[mysqld]下加入一行
skip-grant-tables=1
- 1
- 2
- 3
重新启动Mysql服务
[root@7Core ~]# systemctl restart mysqld.service
- 1
使用Root登录数据库、使用mysql数据库、修改root密码、退出数据库
[root@7Core ~]# mysql -u root
mysql> use mysql;
mysql> update user set authentication_string = password('新密码'),password_last_changed=now() where user='root';
mysql> exit;
- 1
- 2
- 3
- 4
再次打开my.cnf,将skip-grant-tables=1删掉,保存退出
[root@7Core ~]# vi /etc/my.cnf
#删除skip-grant-tables=1
- 1
- 2
重启Mysql服务
mysql 5.6忘记密码操作 1.添加忘记密码启动模式 vim /etc/my.cnf 在[mysqld]目录下增加:skip-grant-tables (这个是代表跳过密码权限的设置,建议在socket=/var/lib/mysql/mysql.sock这个配置下面添加。) 保存退出,重启MySQL 2.更新MySQL密码 #mysql mysql>use mysql; mysql>update user set password = password (‘需要设置的密码’) where user = ‘root’ and host = ‘localhost’; mysql>flush privileges; 3.重启MySQL 将/etc/my.cnf 文件中修改的部分还原,也就是之前更改的那个skip-grant-tables这个一定要注释掉或者删除,建议删除。 service mysqld restart