Skip to content

Instantly share code, notes, and snippets.

@poudelmadhav
Last active March 5, 2024 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poudelmadhav/3a3310a70849c29846e8d81892e2fa9f to your computer and use it in GitHub Desktop.
Save poudelmadhav/3a3310a70849c29846e8d81892e2fa9f to your computer and use it in GitHub Desktop.
Change root mysql password and auth plugin (known case)
-- 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.
drop user {user}@localhost;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment