安装后MySQL后 去查看日志并未查到初始密码,那怎么办尼,解决呗,不解决登录不上去啊 哈哈哈
在MySQL 配置文件中 【mysqld】模块里添加 skip-grant-tables ##(服务器不在加载权限判断)
vim /etc/my.cnf
重启服务
systemctl restart mysqld
再次尝试登录
mysql -uroot 回车
现在已经进入了mysql 里面 就可以开始修改密码了
修改语句
use mysql
alter user 'root'@'localhost' identified by '123456'; ##123456是设置的密码
看报错提示The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement ##运行的时候加入了--skip-grant-tables 选项 所以不能运行该条语句
这时候我们只需要刷新一下权限就可以了
flush privileges;
再次执行修改语句
alter user 'root'@'localhost' identified by '123456';
现在已经修改成功了 退出数据库,去配置文件注释刚刚添加的--skip-grant-tables
重启数据库
systemctl restart mysqld
使用刚刚修改的密码登录
mysql -uroot -p123456
可以用了,快去干活吧!