Install it on the MAC today
AfterMySQL, mysql assigned a default password by default, but when you log in with the default password on the terminal, it will always indicate a mistake that authorized failure: Access Denied for User ‘Root’@’LocalHost’ (USING Passwork) As shown in the figure:
Since I can’t log in nowdatabase
In, it is impossible to talk about changing passwords and adding users. Fortunately, mysql also provides a method of exempting a password check to enter the database. We first use this method to log in to the database. Then replace the default password, the above problem can be solved ~ The specific operation is as follows
This operation, the corresponding different operating files under different platforms
MAC system The configuration file is the MySQL installation directory support_file my-default file
Need to note: The default configuration file does not have the writing permissions. You need to use the chmod command to add the writing permissions to the file to change
ps: The configuration file of the Windows system is mysql installation of the My.ini file to install the root directory
Open the configuration file we just found, and then find it in it
[mysqld]This item, and then add it under this configuration item
skip-grant-tablesThis configuration, and then save the file.
In order to take effect on the previous configuration item, we need to restart mysql service
MAC system can restart in the system preference:
Windows system can pass: right -click on my computer-> Service-> Find the MySQL service to restart
Linuxsystem can be used: service mysqld restart to restart
and then enter the terminal again, knock in
mysql -u root -pcommand and then return to the car. When you need to enter the password, press the ENTER button directly, and you can log in to the database without the password
set password for 'username'@'host' = password('newpassword')command modify the new password.
After we changed the default password, we entered the previous configuration file again, deleted the configuration row of the password to the password, and turned into the original configuration of the system. Restart the MySQL service, and you can solve this problem next time you log in.
If you think the above operation is too troublesome, you can use the shortcuts below to achieve the above effect. For the MAC system as an example:
/usr/local/mysql/support-fileIn this directory, then follow the steps on the picture to operate
After entering the security mode of MySQL, type the four -line configuration circled in the figure (must be entered one by one), and after the input is completed
contrl+zkey end input
and then use mysql -u root -p in the terminal.
pass, you can use the new password of PASS next time. The effect is the same as the above operation.