今天用yum安装mysql,yum install mysql-server 直接安装,安装完发现登录时需要密码,当时就懵逼,下面是当时查的一些东西:
编辑mysql的配置文件:vi /etc/my.cnf
找到[mysqld]在之后添加:skip-grant-tables;
保存退出后重启mysql:service mysqld restart
直接登陆mysql而不需要密码:mysql -u root
查看
更改密码,MySQL 版本在5.7之前的话,在mysql中输入:update mysql.user set password=password('root') where user='root';
MySQL版本在5.7之后的输入: update mysql.user set authentication_string=password('root') where user='root';
这是因为MySQL5.7版本之后,user表中的password字段被替换成了authentication_string字段
刷新权限:flush privileges;
退出:exit;
将my.cnf文件修改为之前的方式。
重新密码登录mysql:mysql -uroot -proot