To change the MySQL password on a Mac system, follow these steps:
- Open a terminal and log in to the MySQL server as an administrator.
sudo mysql -u root -p
-
Enter admin password
-
Switch to MySQL database
use mysql;
- view current user list
select user,host from user;
-
Find the user whose password needs to be changed. For example
john
, the user name is the host address.%
-
Modify user password
update user set authentication_string=password('new_password') where user='john' and host='%';
- Refresh permissions
flush privileges;
- exit mysql
exit
- Restart the MySQL service
sudo service mysql restart
Note: Versions after MySQL 8.0 use caching_sha2_password
for password authentication, you must use ALTER USER
the command or use to set the password when creating a user identified with caching_sha2_password by 'password'
to log in successfully.