今天用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