MySQL temporary table name is per connection, unique for each connection safely use it

Source: Internet
Author: User

I understand temporary table S are dropped automatically. but are the table S which are created unique? I. e. shocould I create a different name for the table or does mysql sort this out?

CreateTemporary TableTemp1 type = heap select * from MERs
.
.
PHP Database Report stuff here ....
.
.
DropTemporary TableTemp1

This createsTemporary TableCalled temp1 and is populated from MERs.

1. What happens if 2 users run the code at near the same time? Will the temp1TableBe upted?

2. What happens if 1 user fires up 2 browser windows and runs the script at near the same time?

3. Is it really necessary to dropTableAt the end of the Code.MySQLSays thatTemporary TableS are automatically dropped.

I cocould create a random name rather than temp1 that shocould sort it?

Note that the type = heap doesn't really matter here. The same problem shoshould exist if heap or not: Does creatingTemporary TableCreate temp1 in seperate user space?
----------------------------------------------------------------------------------

Frank,

This is what I got from mysql docs:

" A temporary table will automatically be deleted if a connection dies and the name is per connection. this means that two different connections can both use the same temporary table name without conflicting with each other or with an existing table of the same name. (The existing table is hidden until the temporary table is deleted .) "

so this means you can safely use any name for your temporary table .

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.