Skip to content

Instantly share code, notes, and snippets.

@milose
Last active December 3, 2016 17:02
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 milose/b4b401d06f9b1a2e68f7 to your computer and use it in GitHub Desktop.
Save milose/b4b401d06f9b1a2e68f7 to your computer and use it in GitHub Desktop.
MySQL user queries

Quick snippets

User info

Show all users and hosts

SELECT User, Host FROM mysql.user;

Show grants for logged in user

SHOW GRANTS;

Show all grants for a user

SHOW GRANTS FOR root;

Show all grants for a user and a host

SHOW GRANTS FOR root@'localhost';

Create

Administrator with local access

CREATE USER 'milos'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'milos'@'localhost' WITH GRANT OPTION;
GRANT RELOAD, PROCESS ON *.* TO 'milos'@'localhost';

Administrator with access from anywhere

CREATE USER 'milos'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'milos'@'%' WITH GRANT OPTION;
GRANT RELOAD, PROCESS ON *.* TO 'milos'@'%';

Create user and add privileges to the database

CREATE USER 'custom'@'localhost' IDENTIFIED BY 'password';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON custom_database.* TO 'custom'@'localhost';
published: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment