Last active
June 18, 2024 10:13
-
-
Save SimpleBackups/bb6c09c3b78cb837c66b8a0aae9e1a05 to your computer and use it in GitHub Desktop.
Discover how to effectively manage user permissions in MySQL
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
# Reference: https://simplebackups.com/blog/how-to-create-and-grant-permissions-to-a-mysql-user/ | |
# How to create a User in MySQL | |
CREATE USER ‘username’@’hostname’ IDENTIFIED BY ‘password’; | |
# How to show the list of users in MySQL | |
SELECT * FROM mysql.user; | |
# Show currently logged MySQL users | |
SELECT current_user(); | |
SELECT user, host, command FROM information_schema.processlist; | |
# How to show all MySQL users | |
SELECT * FROM mysql.user; | |
# How to grant ALL privileges to a MySQL User | |
GRANT ALL PRIVILEGES ON database_name.* TO ‘username’@’hostname’; | |
# How to grant specific privileges to a MySQL User | |
GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, on *.* TO 'username'@'localhost' | |
# How to show MySQL user permission | |
SHOW GRANTS FOR “username”@”localhost” ; | |
# Remove privileges from a MySQL User | |
REVOKE permission_1, permission_2 ON database_name.table_name FROM 'username'@'localhost'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment