Home >Database >Mysql Tutorial >Why Doesn\'t My MySQL `mysql.user` Table Have a `password` Column on macOS?
MySQL User Table Password Column Discrepancy on OSX
When attempting to change the MySQL root password on macOS, users may encounter an error indicating that the 'password' column does not exist in the 'mysql.user' table. This can be confusing, as the 'password' field is typically associated with storing user passwords in the MySQL database.
The reason for this discrepancy is that in MySQL 5.7, the 'password' column was removed from the 'mysql.user' table and replaced with the 'authentication_string' column. This change was made to enhance security by storing passwords using a newer and more secure hashing algorithm.
To change the MySQL root password on macOS with MySQL 5.7, follow these steps:
Open a terminal window and type the following command to connect to MySQL using the 'mysql' command-line client:
mysql -uroot -p
If the 'authentication_string' column does not exist in the 'mysql.user' table, create it using the following command:
ALTER TABLE mysql.user ADD authentication_string TEXT;
Update the MySQL root user's password by setting the 'authentication_string' column to the new password using the following command:
UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE user='root';
Flush the MySQL privileges to apply the changes:
FLUSH PRIVILEGES;
Exit the MySQL client:
exit
You should now be able to log into MySQL using the new root password. This change allows you to enhance the security of your MySQL installation while still maintaining the functionality of user password management.
The above is the detailed content of Why Doesn\'t My MySQL `mysql.user` Table Have a `password` Column on macOS?. For more information, please follow other related articles on the PHP Chinese website!