Skip to content

Instantly share code, notes, and snippets.

@viral32111
Last active March 2, 2022 22:51
Show Gist options
  • Select an option

  • Save viral32111/6d45744a6726289a956920ab69b6f279 to your computer and use it in GitHub Desktop.

Select an option

Save viral32111/6d45744a6726289a956920ab69b6f279 to your computer and use it in GitHub Desktop.
MySQL Reference

MySQL Reference

Create User

Adds a new user for connecting to the database server.

CREATE USER 'name'@'host' IDENTIFIED BY 'password';

Use a different authentication plugin for compatibility with some applications.

CREATE USER 'name'@'host' IDENTIFIED WITH 'mysql_native_password' BY 'password';

Delete User

Removes an existing user.

DROP USER 'name'@'host';

Rename User

Changes a user's name or host, and maintains grants.

RENAME USER 'user'@'host' TO 'user'@'host';

List Users

Shows all of the existing users.

SELECT User,Host,plugin FROM mysql.user;

Update User Password

Changes the password for an existing user.

ALTER USER 'name'@'host' IDENTIFIED BY 'password';

Grant Privileges

Add permissions to an existing user.

GRANT ALL PRIVILEGES ON database.table TO 'name'@'host';

Individual permissions can also be specified.

GRANT SELECT, UPDATE, INSERT, DELETE ON database.table TO 'name'@'host';

Revoke Privileges

Remove permissions from an existing user.

REVOKE ALL PRIVILEGES ON database.table FROM 'name'@'host';

Individual permissions can also be specified.

REVOKE SELECT, UPDATE, INSERT, DELETE on database.table from 'name'@'host';

List User Privileges

Shows all of the permissions for an existing user.

SHOW GRANTS FOR 'name'@'host';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment