1, a terminal opening close MySQL: brew services stop mysql
(I mac brew installation command mysql)
2, execute mysqld --skip-grant-tables
commands (-skip-grant-tables means that the time to start MySQL service permission to skip the authentication table), if the error unknown option --skip-grant-table
is executedmysqld -nt --skip-grant-tables
3, the second terminal performs open mysql -uroot -p
prompted for a password, enter directly (no password)
4, select the database:use mysql;
5, update the root password:update user set authentication_string=password('新密码') where user='root' and Host='localhost';
6, refresh permissions:flush privileges;
7, exit:quit
8, re-login: mysql -uroot -p
prompt for a password, then enter a password to login.