sentos安装MySQL:centos7安装mysql5.7_shuair的博客-CSDN博客_centos7 安装mysql5.7
- 设置为无密码登录(取消登录验证)
- 重置密码
- 取消无密码登录
修改mysql的配置文件,默认位置:/etc/my.cnf
vim /etc/my.cnf
修改[mysqld]节点,添加skip-grant-tables,表示 跳过权限验证
- [mysqld]
- # 其它配置...
- # 其它配置...
- skip-grant-tables
保存,重启mysql
- # systemctl restart mysqld
- systemctl stop mysqld
- systemctl start mysqld
重启mysql后可能会报错
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
这种情况多数是配置文件中仍然存在权限相关的配置,暂时先注释掉,比如下面列举的配置
- #validate_password_length = 4
- #validate_password_policy = 0
此时即可无密码登录了(也无需用户名)
mysql
使用mysql数据库
use mysql
修改密码
低版本
update user set Password = password('你的新密码') where user = 'root';
高版本(mysql57亲测可用)
update user set authentication_string=password('new password') where user = 'root';
将第1步注释掉的配置还原回来,重启服务。此时就已经修改好密码了。