Ubuntu 下Mysql 安装时密码问题

1.安装以后没有设置密码

sudo cat /etc/mysql/debian.cnf

通过这个查看mysql的默认用户名和密码

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = cOrWdhKDBv7LS86s
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = cOrWdhKDBv7LS86s
socket   = /var/run/mysqld/mysqld.sock

2.正常登录mysql,修改密码

 alter user'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
 flush privileges;

3.重新登陆即可