Cloud Service >> Knowledgebase >> Database >> How To Create a New User and Grant Permissions in MySQL
submit query

Cut Hosting Costs! Submit Query Today!

How To Create a New User and Grant Permissions in MySQL

Managing users and permissions in MySQL ensures secure and efficient database operations. Here’s a step-by-step guide.

Creating a New User

Log in to MySQL as root:

shell

mysql -u root -p

Create a new user:

sql

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

username: The new user's name.

host: Specifies access location (e.g., % for all hosts, localhost for local access).

Granting Permissions

Grant specific permissions:

sql

GRANT SELECT, INSERT ON database_name.* TO 'username'@'host';

Grant all privileges:

sql

GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'host';

Apply changes:

sql

FLUSH PRIVILEGES;

Viewing and Revoking Permissions

View user privileges:

sql

SHOW GRANTS FOR 'username'@'host';

Revoke privileges:

sql

REVOKE privilege_type ON database_name.* FROM 'username'@'host';

Conclusion

 

Proper user management is critical for database security. For hosting your databases securely, consider Cyfuture Cloud, which offers scalable and reliable database hosting.

Cut Hosting Costs! Submit Query Today!

Grow With Us

Let’s talk about the future, and make it happen!