mysql5.7版本在安装后,使用mysql -uroot -p 回车后不需要输入密码即可进入到数据库中
1.进入到debian.cnf配置文件中,获取默认的用户名和密码
命令:
sudo gedit /etc/mysql/debian.cnf
运行后获得user 和 password
2.使用user和password登陆mysql
如下图
mysql -udebian-sys-maint -p
3.修改用户名和密码
use mysql
update mysql.user set authentication_string=password('mysql') where user='root' and Host ='localhost';
update user set plugin="mysql_native_password";
flush privileges;
quit;
4.完成修改后重启mysql服务器
sudo service mysql restart