- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to prevent a user from accessing a specific schema in MySQL?
To prevent a user from accessing a specific schema, you need to use delete command. Following is the syntax −
DELETE FROM mysql.db WHERE Db IN("yourSpecificSchema","yourSpecificSchema\_%") AND User = "yourUserName" AND Host = "yourHostName";
Let us implement the above syntax to prevent a user from accessing a specific schema. First of all, let us display all users and host from MySQL.user table.
mysql> select user,host from MySQL.user;
This will produce the following output −
+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % | | mysql.sys | % | | root | % | | @UserName@ | localhost | | Adam Smith | localhost | | Chris | localhost | | David | localhost | | James | localhost | | John | localhost | | John Doe | localhost | | User1 | localhost | | am | localhost | | hbstudent | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | +------------------+-----------+ 18 rows in set (0.00 sec)
Here, we will prevent user ‘Chris’ with host name ‘localhost’ from accessing a specific schema which has the name ‘sample’ −
mysql> DELETE FROM mysql.db WHERE Db IN("sample","sample\_%") AND User="Chris" AND Host="localhost"; Query OK, 0 rows affected (0.00 sec)
After executing the above query, you need to use FLUSH.
mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.06 sec)
Advertisements