Permission to drop views but not drop tables - mysql

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.

Related

How to remove user privileges associated with the dropped table?

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?

In My SQL i want user to restrict the Drop table and Drop database

In mysql i want trigger for drop table and alter table, like in sql server we have.
FOR DROP_TABLE, ALTER_TABLE triggers
Is there any thing which i can do for it? basically i want the functionality that user should not able to delete/alter the table, we can even achieve it by providing restrictive permissions, But we have application in which the customer purchased the sql server so they have root user login and then can do it, so if we add trigger then only i think we can restrict it,
Same thing i need to drop database, In SQL server we have
FOR DROP_DATABASE , DROP_TRIGGER ,ALTER_TRIGGER
Is there any way to do it in mysql
Thanks in advance
You could use the REVOKE command to remove the ALTER and DROP permissions for the user.
https://dba.stackexchange.com/questions/27372/blocking-drop-database-command

Grant users to create database with username

In phpmyadmin I want to grant users to create and delete databases but this access should be limited to a specific prefix.
My users have 3 different accounts on PhpMyAdmin: username_ro (for only reading), username_rw (for reading and writing) and username_admin (for creating other databases and tables into their account)
I want them to be able to create a database username_website but I don't want them to be able to create database theother_website. They should also be able to drop username_website but unable to drop theother_website
How can I do this with sql or PhpMyAdmin.
Thanks in advance.
With some trial and error I have found a solution. By doing this query I was able to create and drop database username_website but I wasn't able to create or drop database theother_clients
GRANT ALL PRIVILIGES
ON `username\_%`.*
TO 'username_admin'#'localhost';
PS. the query is a little edited. I changed the rights I actually gave with ALL PRIVILIGESand I changed the actual username with username.

Create user with Drop privilege for just tables Not DB

Can someone help me with privileges here. I need to create a user that can DROP tables within databases but cannot DROP the databases?
MySQL DB version:5.0.95
If he can drop tables, he can simply enter the query DROP TABLE *; effectively dropping the contents of the database. There is no plus to allowing a user to drop only tables, and thus I don't think there is a way to do so.

Is it necessary to drop temporary tables in MySQL?

I'm having a problem dropping a temporary table. The user account does not have the 'drop' privilege. I don't want to grant that privilege due to security reasons.
I tried to find a privilege like 'drop temporary' but there isn't. It seems the only option is to remove all the 'drop table' statements. I know that the temporary tables will be automatically dropped after the DB sessions end.
However, I'm not sure if there are any side effects leaving this job to MySQL. Please, advice.
Temporary tables are dropped automatically as soon as you disconnect from database
A TEMPORARY table is visible only to the current connection, and is dropped automatically when the connection is closed
http://dev.mysql.com/doc/refman/5.1/en/create-table.html
So - create them, use and don't bother of theirs deletion
It will use current machine's Ram space.
So better idea is drop the temporary table on the next step ,once its use is over
If the user has CREATE TEMPORARY TABLES privilege, he can perform DROP TABLE, INSERT, UPDATE and SELECT.
Please see: https://dev.mysql.com/doc/refman/5.7/en/privileges-provided.html#priv_create-temporary-tables