How To Create a User and Grant Permissions in MySQL

0 min read 132 words

How to create a user

CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

How to delete a user

DROP USER 'myuser'@'localhost';

How to grant permissions

GRANT ALL PRIVILEGES ON * . * TO 'myuser'@'localhost';

How to apply those permissions

FLUSH PRIVILEGES;

Going a bit deeper

Different types of Grants

ALL PRIVILEGES : Full access to everything, globally unless restricted to a database

CREATE : Create databases and tables

DROP : Delete databases and tables

DELETE : Delete rows from tables

INSERT : Insert rows in tables

SELECT : Read data from tables

UPDATE : Update rows in tables

GRANT OPTION : Grant or remote other user’s permissions

How to use them

GRANT permission_type ON database_name.table_name TO 'myuser'@'localhost';

How to revoke them

REVOKE permission_type ON database_name.table_name FROM 'myuser'@'localhost';

How to show them

SHOW GRANTS myuser;
Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags