Create user with Drop privilege for just tables Not DB - mysql

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.

Related

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

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.

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.

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