-
一、以安全模式登录
# Stop MySQL sudo service mysql stop # Start MySQL manually, without permission checks or networking. sudo mysqld_safe --skip-grant-tables & # Log in without a password. mysql -u root
二、修改密码
UPDATE mysql.user SET authentication_string=PASSWORD('NEW-PASSWORD'),plugin='mysql_native_password' WHERE User='root' ;
flush privileges; EXIT;三、重启数据库
新开窗口 mysqladmin -uroot -p shutdown ==>新密码测试关掉数据库,成功关闭就证明修改成功,此步骤也可能失败
# Start the MySQL service normally. sudo service mysql start