Mac安装mysql 5.7 出现Access denied for user ‘root‘@‘localhost‘ (using password: YES)

Write a custom catalog title here

Error when logging in to MySQL

Use mysql -u root -p to enter the password and report an error
Access denied for user 'root'@'localhost' (using password: YES)

Reason for error

A default password is automatically created when mysql is installed on the Mac. The password in the database may be encrypted for some reason.

Solution

  1. cd /usr/local/mysql/data/, Find the data folder
  2. Direct access is not possible, you need to grant access permissions to the folder, here for convenience, grant all permissions directly (the actual operation is based on personal needs)sudo chmod -R 777 /usr/local/mysql/data
  3. Enter the folder, find two files ib_logfile0 and ib_logfile1, delete them directly rm -f ib_logfile0 rm -f ib_logfile1
  4. Find mysql in the system preferences and stop the service
  5. Enter the terminal type: cd /usr/local/mysql/bin/
    After login Enter administrator privileges sudo su
    input Enter the following command to disable the authentication function mysql ./mysqld_safe --skip-grant-tables &
    mysql will automatically restart after a carriage return (state preferences will become mysql running)
  6. Enter the command ./mysql and press Enter (applicable for versions after 5.6) to
    update MySQL.user set authentication_string=password('新的密码') where user='root' ;
    refresh the permissions flush privileges;
    7. After finishing, exit, and then log in to mysql again with the newly set password
    8. After entering mysql, execute itshow databases;
  7. There may be an operation that asks you to set the password again, and
    ALTER USER 'root'@'localhost' IDENTIFIED BY '你的新密码';you are done at this time.

Guess you like

Origin blog.csdn.net/Evain_Wang/article/details/112062726