Is it necessary to drop temporary tables in MySQL? - 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

Related

mysql temporary table privileges

I am using mariadb as my application backend.
i need to create a temporary table (which is temporary per connection, so when the connection is lost it will gone; that is what i want), but i need store a value which should be constant so the user only read it (no update, delete or ... only select), and this value is different in every connection.
so my question is can i grant only select privilege on a specific temporary table in mysql or mariadb?
according to the MySQL 5.1 Documenation https://dev.mysql.com/doc/refman/5.1/en/privileges-provided.html#priv_create-temporary-tables, it can't be done.
in the documentation it is suggested to use another database dedicated to temporary tables, with specified privilege for it.

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.

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.

Transactional ALTER statements in MySQL

I'm doing an update to MySQL Database which includes MySQL scripts that make ALTER TABLE sentences, as well as DIU sentences (delete, insert, update).
The idea is to make a transactional update, so if a sentence fails, a rollback is made, but if I put ALTER TABLE sentences or others specified in http://dev.mysql.com/doc/refman/5.0/en/implicit-commit.html an implicit commit is made, so I can't make a complete rollback, because the indicated operations remains commited.
I tried to use mysqldump to make a backup which is used in case of error (mysql returns distinct to zero), but it is too slow and can fail too.
What can I do? I need this to ensure that future updates are safe and not too slow, because databases contains between 30-100 GB of data.
dump and reload might be your best options instead of alter table.
From mysql prompt or from the database script:
select * from mydb.myt INTO OUTFILE '/var/lib/mysql/mydb.myt.out';
drop table mydb.myt;
create tablemyt(your table ddl here)
load data infile '/var/lib/mysql/mydb.myt.out' INTO TABLE mydb.myt;
Check this out:
http://everythingmysql.ning.com/profiles/blogs/whats-faster-than-alter
I think it offers good guidance on "alternatives to alter".
Look at pt-online-schema change.
You can configure it to leave the 'old' table around after the online ALTER is completed. The old table will have an underscore prefix. If bad things happen, drop the tables you altered and renamed the OLD tables to the original tables. If everything is OK, then just drop the OLD tables.
http://www.percona.com/doc/percona-toolkit/2.1/pt-online-schema-change.html

How do I remove a MySQL database?

You may notice from my last question that a problem caused some more problems, Reading MySQL manuals in MySQL monitor?
My database is now unusable partly due to my interest to break things and my inability to look at error messages. I know that I should not reuse primary keys, but I would like to use them again after the removal of the database that I deteriorated. So
How can I correctly remove a MySQL database?
From the MySQL prompt:
mysql> drop database <db_name>;
If your database cannot be dropped, even though you have no typos in the statement and do not miss the ; at the end, enclose the database name in between backticks:
mysql> drop database `my-database`;
Backticks are for databases or columns, apostrophes are for data within these.
For more information, see this answer to Stack Overflow question When to use single quotes, double quotes, and backticks?.
If you are using an SQL script when you are creating your database and have any users created by your script, you need to drop them too. Lastly you need to flush the users; i.e., force MySQL to read the user's privileges again.
-- DELETE ALL RECIPE
drop schema <database_name>;
-- Same as `drop database <database_name>`
drop user <a_user_name>;
-- You may need to add a hostname e.g `drop user bob#localhost`
FLUSH PRIVILEGES;
Good luck!
drop database <db_name>;
FLUSH PRIVILEGES;
I needed to correct the privileges.REVOKE ALL PRIVILEGES ONlogs.* FROM 'root'#'root'; GRANT ALL PRIVILEGES ONlogs.* TO 'root'#'root'WITH GRANT OPTION;
For Visual Studio, in the package manager console:
drop-database
If you are working in XAMPP and your query of drop database doesn't work then you can go to the operations tag where you find the column (drop the database(drop)), click that button and your database will be deleted.