⼀ .进⼊MySql配置⽂件中
vi /etc/my.cnf
在最后⼀⾏添加免密码登陆:
skip-grant-tables
:wq 保存退出
⼆.重启MySql
service mysql restart
或
systemctl restart mysqld.service
三. 登陆数据库
mysql -uroot -p
让输⼊密码直接回⻋就可以
四.修改MySql密码
use mysql;
# newPassword 是你⾃⼰设置的新密码
update user set authentication_string= password("newPassword")where user='root';
退出
exit;
五.删除免登录的代码
vi /etc/my.cnf
删除
skip-grant-tables
:wq 保存退出
六. 重启MySql
service mysql restart
或
systemctl restart mysqld.service
七. 登陆
mysql -uroot -p
Enter password:
输⼊你刚刚设置的密码
登陆成功