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
cd /usr/local/mysql/data/
, Find the data folder- 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
- Enter the folder, find two files ib_logfile0 and ib_logfile1, delete them directly
rm -f ib_logfile0 rm -f ib_logfile1
- Find mysql in the system preferences and stop the service
- Enter the terminal type:
cd /usr/local/mysql/bin/
After login Enter administrator privilegessudo 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) - 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 permissionsflush privileges;
7. After finishing, exit, and then log in to mysql again with the newly set password
8. After entering mysql, execute itshow databases;
- 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.