Last active
March 5, 2024 11:04
-
-
Save poudelmadhav/3a3310a70849c29846e8d81892e2fa9f to your computer and use it in GitHub Desktop.
Change root mysql password and auth plugin (known case)
This file contains 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 mysql_native_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. |
This file contains 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; |
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: