How to change the password of MySQL on Mac system (nanny level tutorial)

To change the MySQL password on a Mac system, follow these steps:

  1. Open a terminal and log in to the MySQL server as an administrator.
sudo mysql -u root -p
  1. Enter admin password

  2. Switch to MySQL database

use mysql;
  1. view current user list
select user,host from user;
  1. Find the user whose password needs to be changed. For example john, the user name is the host address.%

  2. Modify user password

update user set authentication_string=password('new_password') where user='john' and host='%';
  1. Refresh permissions
flush privileges;
  1. exit mysql
exit
  1. Restart the MySQL service
sudo service mysql restart

Note: Versions after MySQL 8.0 use caching_sha2_passwordfor password authentication, you must use ALTER USERthe command or use to set the password when creating a user identified with caching_sha2_password by 'password'to log in successfully.

Guess you like

Origin blog.csdn.net/yueyeguzhuo/article/details/129340672