LINUX MYSQL

Grant Permissions to a MySQL User on Linux via Command Line

MYSQL Articles, Errors and Fixes
MYSQL Articles, Errors and Fixes

Pre-Flight Check

These directions square measure meant for granting a MySQL user permissions on LINUX system via the instruction

I’ll be engaging from a Liquid internet Core Managed CentOS six.5 server, and I’ll be logged in as root.

Login to MySQL

First we’ll login to the MySQL server from the instruction with the following command:

mysql -u root -p

In this case, I’ve mere the user root with the -u flag, so used the -p flag so MySQL prompts for a parole. Enter your current parole to finish the login.

If you would like to alter your root (or any other) parole within the info, then follow this tutorial on ever-changing a parole for MySQL via the command

You should currently be at a MySQL prompt that appears terribly almost like this:

mysql>

If you haven’t nonetheless created a MySQL user, please visit our tutorial on making a MySQL user.

Grant Permissions to MySQL User:

The basic syntax for granting permissions is as follows:

GRANT permission ON database.table TO 'user'@'localhost';

Here is a brief list of usually used permissions :

ALL – enable complete access to a particular info. If a info isn’t such, then enable complete access to the whole lot of MySQL.

CREATE – enable a user to make databases and tables.

DELETE – enable a user to delete rows from a table.

DROP – enable a user to drop databases and tables.

EXECUTE – enable a user to execute hold on routines.

GRANT possibility – enable a user to grant or take away another user’s privileges.

INSERT – enable a user to insert rows from a table.

READ  Remove a MySQL User on Linux via Command Line

SELECT – enable a user to pick knowledge from a info.

SHOW DATABASES– enable a user to look at an inventory of all databases.

UPDATE – enable a user to update rows in a table.

 

Example #1: To grant produce permissions for all databases * and every one tables * to the user we created within the previous tutorial, testuser , use the following command:

GRANT CREATE ON *.* TO 'testuser'@'localhost';

Using an asterisk (*) within the place of the information or table is a very valid possibility, and implies all databases or all tables.

Example #2: To grant testuser the flexibility to drop tables within the specific information, tutorial_database , use the DROP permission:

GRANT DROP ON tutorial_database.* TO 'testuser'@'localhost';

When finished making your permission changes, it’s good practice to reload all the privileges with the flush command!

FLUSH PRIVILEGES;

View Grants for MySQL User:

After you’ve granted permissions to a MySQL user you’ll probably want to double check them. Use the following command to check the grants for testuser:

SHOW GRANTS FOR 'testuser'@'localhost';

Output:

+---------------------------------------------------------------------+
| Grants for testuser@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+

 

About the author

Venkatesan Prabu

Venkatesan Prabu

Wikitechy Founder, Author, International Speaker, and Job Consultant. My role as the CEO of Wikitechy, I help businesses build their next generation digital platforms and help with their product innovation and growth strategy. I'm a frequent speaker at tech conferences and events.

Add Comment

Click here to post a comment