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:

[pastacode lang=”sql” manual=”mysql%20-u%20root%20-p” message=”” highlight=”” provider=”manual”/]

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:

[pastacode lang=”sql” manual=”mysql%3E” message=”” highlight=”” provider=”manual”/]

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:

[pastacode lang=”sql” manual=”GRANT%20permission%20ON%20database.table%20TO%20’user’%40’localhost’%3B” message=”” highlight=”” provider=”manual”/]

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.

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:

[pastacode lang=”sql” manual=”GRANT%20CREATE%20ON%20*.*%20TO%20’testuser’%40’localhost’%3B” message=”” highlight=”” provider=”manual”/]

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:

[pastacode lang=”sql” manual=”GRANT%20DROP%20ON%20tutorial_database.*%20TO%20’testuser’%40’localhost’%3B” message=”” highlight=”” provider=”manual”/]

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

[pastacode lang=”sql” manual=”FLUSH%20PRIVILEGES%3B” message=”” highlight=”” provider=”manual”/]

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:

[pastacode lang=”sql” manual=”SHOW%20GRANTS%20FOR%20’testuser’%40’localhost’%3B” message=”” highlight=”” provider=”manual”/]

Output:

[pastacode lang=”less” manual=”%2B———————————————————————%2B%0A%7C%20Grants%20for%20testuser%40localhost%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7C%0A%2B———————————————————————%2B%0A%7C%20GRANT%20ALL%20PRIVILEGES%20ON%20*.*%20TO%20’testuser’%40’localhost’%20WITH%20GRANT%20OPTION%20%7C%0A%2B———————————————————————%2B” message=”” highlight=”” provider=”manual”/]

 

Categorized in: