How to remove user privileges associated with the dropped table? - mysql

When I was reading about the DROP TABLE statement in MySQL, I came across the term RESTRICT & CASCADE. On one website, click here to goto that link where I found information stating,
Note that the DROP TABLE statement only drops tables. It doesn’t remove specific user privileges associated with the tables. Therefore, if you create a table with the same name as the dropped one, MySQL will apply the existing privileges to the new table, which may pose a security risk.
It made me curious to know how one can remove user privileges associated with the dropped table?
Also, what are the use of RESTRICT & CASCADE keywords in the DROP TABLE statement?

Related

MySQL: remove a user's permission to delete specific tables

That is the question... I have 30 tables in a database, and I want to avoid deleting information in five tables.
With this I will also understand how to avoid inserting in three tables. Of course, I have created a new user and still don't have any privilege.
Can this mechanic be done?
Use REVOKE:
REVOKE DELETE ON contacts FROM 'user1'#'localhost';
Which would remove the DELETE permission on table contacts.
With mydb.*, for example, you can remove all DELETE permissions on all tables in the database mydb.

MySQL - 'Drop User' vs 'delete from user'

I need to delete database access from some hosts. There are two options:
This option appears to be the best as I don't need to delete individual users
use mysql;
delete from user where host='myhost';
In second option below, I need to delete individual users.
drop user 'user1'#'myhost';
drop user 'user2'#'myhost';
drop user 'user3'#'myhost';
Any idea what is the difference between these options? Any pro and cons?
Thanks
When you use DROP USER Statement it removed one/more accounts + their accounts privileges.
When you use DELETE User it's just an SQL command which effects for table(s).
DROP is always more powerful than delete
Or You can use REVOKE to remove all permeation granted
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user'#'myhost';
Privileges are
ALL PRIVILEGES – grants all privileges to the MySQL user
CREATE – allows the user to create databases and tables
DROP - allows the user to drop databases and tables
DELETE - allows the user to delete rows from specific MySQL table
INSERT - allows the user to insert rows into specific MySQL table
SELECT – allows the user to read the database
UPDATE - allows the user to update table rows
Read More about DROP USER Statement
Modifying the database tables requires a flush privileges call to refresh the cached data. Also, you have to make sure that you manually delete all user AND privileges (e.g., for tables, columns) manually.
Grant/drop user work immediately.
Cf. https://dev.mysql.com/doc/refman/8.0/en/privilege-changes.html

How droping a table from DB affects the views

A veiw is created on table Student.
If i drop the student table will the veiw also drop ? If not what will be the situation ?
The view remains but is invalid. You must explicitly drop the view.
When a table gets dropped all data, indexes, and linked information will be deleted as well.It's been like a row in DB which use delete all the relative column and all the information that was linked to it will be deleted as well.
When a table is dropped, privileges granted specifically for the table
are not automatically dropped. They must be dropped manually.
Be careful with this statement! It removes the table definition and all table data. For a partitioned table, it permanently removes the table definition, all its partitions, and all data stored in those partitions. It also removes partition definitions associated with the dropped table.

Mysql priviléges

for user boss12 i associate the right to modify only the name, But I want to know how to associate that renaming only the student with idStu = 12, i.e he can change the name of the student (idStu = 12) but he can not for the student (idStu = 13).
create database gcr;
use gcr;
create table Student(
idStu int primary key,
nom varchar(30),
moyen real)engine=innodb;
insert into Student values(12,'hassen',15.0);
insert into Student values(13,'ouss',12.0);
create user boss12#localhost
identified by 'enig';
create user prof#localhost
identified by 'gcrgcr';
use mysql;
grant select, update,insert on gcr.Student
to prof#localhost with grant option;
grant update (nom) on gcr.Student
to boss12#localhost with grant option;
Impossible in any straightforward way.
There's no row-level security in the very vast majority of RDBMS.
However, theoretically, you can build the additional level that encapsulates the main dataset + additional row level security data (e.g. table(s) that describes the access grants/policies/restrictions for particular rows + reference to these rules from the main data tables) - and then
But that's quite tricky part, let me tell you - even for reads.
And I'm really not sure is it possible for updates in such a case.
The other way is to set a before-update trigger on the given table, then check whatever conditions you want against the requestor's user - and fail the transaction if needed.
But that, honestly, is a dirty hack in your case - heavily data-depending (thus error prone) and hardly maintainable.
Direct solution for you question is not available . According to my understanding you want user boss12 should able to update only some data in table Student.
for ex, update Student set nom='' where idstu =12 should work but update Student set nom='' where idstu =13 should not work .
This is not possible to control via privilege control You can create view on student table where you want to provide update privilege to user idstu.
sql reference for column level privilege

Permission to drop views but not drop tables

I want to create a user with permission to create and drop views but not drop tables or databases. This is so I can play around when testing my views without the risk of accidentally deleting a table.
There is a GRANT CREATE VIEW privilege but there doesn't appear to be a GRANT DROP VIEW counterpart. GRANT DROP apparently applies to databases, tables and views.
Is this possible in MySQL?
I've been researching this, too, and the answer appears to be No. You can restrict the DROP to only tables/views within one database (or a group of LIKE pattern-matched databases). This will make sure they cannot drop the entire database. Unfortunately, you cannot do pattern-matching on the table/view names. It's either all the tables/views (*) in those databases, or only explicity mentioned tables/views.