Grant Privileges to the MySQL New User

After creating a new user in MySQL, you need to grant privileges to the user to allow them to perform certain operations on databases and tables. Here’s the basic syntax for granting privileges to a user:

GRANT privilege_type ON database_name.table_name TO 'username'@'localhost';

In this syntax, ‘privilege_type’ represents the type of privilege you want to grant, such as SELECT, INSERT, UPDATE, DELETE, etc. ‘database_name’ represents the name of the database that the user will have access to, and ‘table_name’ represents the name of the table within that database that the user will have access to.

For example, to grant the SELECT and INSERT privileges to the user ‘myuser’ on the database ‘mydatabase’ and the table ‘mytable’, you can use the following syntax:

GRANT SELECT, INSERT ON mydatabase.mytable TO 'myuser'@'localhost';

If you want to grant all privileges to the user, you can use the ALL keyword instead of listing individual privileges:

GRANT ALL ON mydatabase.mytable TO 'myuser'@'localhost';

You can also use the * wildcard to grant privileges to all databases or tables:

GRANT SELECT ON *.* TO 'myuser'@'localhost';

Once you’ve granted the necessary privileges to the user, they will be able to perform the specified operations on the specified databases and tables. Note that you need to have the necessary privileges to grant privileges. The MySQL root user has all privileges, so you can use that account to grant privileges. However, it’s generally a good practice to create a separate user with fewer privileges for everyday use.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Back to top button