How to solve the forgotten password of MySQL on Mac

Solution to MySQL forgot password on Mac:
  • Shut down the MySQL service

    • Method 1: Click the Apple icon in the upper left corner of the screen, select "System Preferences", the MySQL icon will be displayed below. After selecting the icon, click the "Stop MySQL Server" button to close the MySQL service.
    • Method 2: Open Terminal, enter it sudo /usr/local/mysql/support-files/mysql.server stop, press Enter, enter the Mac password according to the prompt and press Enter.
  • In the terminal, execute the following commands in sequence

    # 进入目录
    cd /usr/local/mysql/bin/
    
    # 获取权限(根据提示输入mac密码)
    sudo su
    
    # 设置无密码进入
    ./mysqld_safe --skip-grant-tables &
    
    #“control + D”退出编辑
    
    # 进入MySQL monitor
    ./mysql
    
    # 获取更改权限
    FLUSH PRIVILEGES; 
    
    # 重置密码
    ALTER USER 'root'@'localhost' IDENTIFIED BY '你的新密码';
    

Guess you like

Origin blog.csdn.net/szw_yx/article/details/104695784