Last active
April 10, 2025 11:22
-
-
Save poudelmadhav/3a3310a70849c29846e8d81892e2fa9f to your computer and use it in GitHub Desktop.
Change root mysql password and auth plugin (known case)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Plugin can be 'auth_socket', 'mysql_native_password' or 'caching_sha2_password' | |
| SELECT user, authentication_string,plugin,host FROM mysql.user; | |
| -- Change the auth socket plugin to caching_sha2_password of root user | |
| ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password'; | |
| FLUSH PRIVILEGES; | |
| -- Create another user that uses caching_sha2_password as plugin | |
| USE mysql; | |
| CREATE USER '{user}'@'localhost' IDENTIFIED WITH caching_sha2_password BY '{password}'; | |
| GRANT ALL PRIVILEGES ON *.* TO '{user}'@'localhost'; | |
| FLUSH PRIVILEGES; | |
| -- Replace {user} with the user that you want to create and {password} with the password that you want to set. | |
| -- If you like to create user with auth_socket plugin do | |
| USE mysql; | |
| CREATE USER '{user}'@'localhost' IDENTIFIED WITH auth_socket; | |
| GRANT ALL PRIVILEGES ON *.* TO '{user}'@'localhost'; | |
| FLUSH PRIVILEGES; | |
| -- Replace {user} with the user that you want to create and {password} with the password that you want to set. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| drop user {user}@localhost; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More info about granting and revoking privileges: