Tag Archives: MySQL

How To Grant Privilege To Any MySQL Database User ?

GRANT command is be used for giving privilege to any user for accessing database.

GRANT PRIVILEGES ON DATABASE OBJECTS TO USER@HOST IDENTIFIED BY ‘PASSWORD’;

Example:

For granting privilege to user  admin Use:

GRANT ALL PRIVILEGES ON *.* TO ‘admin@localhost’ IDENTIFIED BY ‘secret’;

For specifying the username and password which is used while staring MySQL is:

mysql –h hostname –u username –p password

When you don’t want users to access any other database tables then replace* (as shown below) with database name of that particular user whom you want to limit access to other database tables:

GRANT ALL PRIVILEGES ON ‘store’.* TO ‘admin@localhost’ IDENTIFIED BY ‘secret’;

Run given command with root permission. In the given command ‘store’ correlates to the name of database to which the privileges are assigned.

Listing MySQL Databases

For showing all database:

SHOW DATABASES;

In case you need to filter database by name:

SHOW DATABASES LIKE ‘pattern’;

For complex filtering of database use WHERE Clause:

SHOW DATABASES WHERE conditions;

With WHERE clause one can use regular expressions like ‘<‘ and ‘>’ operators, string functions etc. for filtering records returned by SHOW DATABASES.