MySQL 是使用终端命令进行安装的,没有提示设置密码。因此,找到 /etc/mysql/debian.cnf 文件:

将 user 和 password 记住,这将是我们首次进入 mysql 的账号密码,命令为:
mysql -u 用户名 -p

用户名为刚才我们查到的 user 字段,密码为 password 字段。
下面,进行更改 root 用户的密码操作:
use mysql; ## 选择 mysql 数据库
update user set plugin="mysql_native_password",authentication_string=password('root') where user="root";
## authentication_string 字段为密码字段,password() 函数里面需要填的就是新密码
FLUSH PRIVILEGES;
退出 mysql,使用 root 用户登录:

至此,mysql 密码修改成功。
网友评论