首先置空密码后可直接登录
1. cd /usr/local/mysql/bin/
2. sudo su ./mysqld_safe --skip-grant-tables &
3. 可能需要输入系统密码,正确输入后,现在的数据库密码将置为空
需要重新设置密码的话
update user set password=password("你的密码") where user="root";
如果是5.7的版本,那么应该是
update user set authentication_string=password("你的密码") where user="root";